實體類註解出錯: Could not determine type for: java.util.Set, at table: adm_role
阿新 • • 發佈:2019-01-08
配置了User與Role的多對多關係,啟動測試,提示如下錯誤:
Could not determine type for: java.util.Set, at table: adm_role, for columns: [org.hibernate.mapping.Column(users)]
//省略若干錯誤資訊 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE] ... 40 common frames omitted Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: adm_role, for columns: [org.hibernate.mapping.Column(users)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.mapping.Property.isValid(Property.java:241) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.mapping.RootClass.validate(RootClass.java:270) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.cfg.Configuration.validate(Configuration.java:1358) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) ~[hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final] ... 48 common frames omitted
主要原因是因為出現,有的JPA註解用在 getter 方法上,有的註解使用在 實體類的屬性上。必須統一,要麼在方法上,要麼在屬性上。出錯的主要原因是個人喜歡把 @註解 都放在屬性上,因為檢視程式碼的時候基本屬性都定義在最前面,比較一目瞭然,否則定義在getter方法上還有去找,費神。 但是我所有的 實體類都繼承自抽象類: IdEntity,,IdEntity把JPA註解在 getter方法,所以出現了以上錯誤。