JPA建立實體類錯誤解決
阿新 • • 發佈:2019-02-04
今天使用使用eclipse建立註解實體類時發生以下錯誤:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899) at org.springframework.orm.jpa.vendor.SpringHibernateEjbPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateEjbPersistenceProvider.java:51) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562) ... 21 more Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: company, for columns: [org.hibernate.mapping.Column(businesstype)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314) at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:292) at org.hibernate.mapping.Property.isValid(Property.java:239) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:483) at org.hibernate.mapping.RootClass.validate(RootClass.java:270) at org.hibernate.cfg.Configuration.validate(Configuration.java:1327) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1789) at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914) ... 27 more
解決方法:註解要麼寫在欄位上,要麼寫在getXX上,千萬千萬不能混合使用,否則會報這個錯誤!
我的BaseEntity中的註解寫在了方法上,實現類卻寫在了欄位上,導致了以上問題的發生。