异常一:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: This class [class com.xxx.xxx.xxx.xxxxx] does not define an IdClass
原因:由于你在你的实体中增加了多个@Id注解
异常二:
Could not instantiate resultclass: java.lang.Long; nested exception is org.hibernate.HibernateException: Could not instantiate resultclass: java.lang.Long] with root causeorg.hibernate.HibernateException: Could not instantiate resultclass: java.lang.Long
原因:因为你使用了setResultTransformer
session.createSQLQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).getSingleResult();
正确写法:
Long.parseLong(session.createSQLQuery(sql).getSingleResult().toString());