0
我正處於休眠映射異常,同時使用@ElementCollection
異常,同時使用@ElementCollection
錯誤消失時,我不使用@ElementCollection
,我已經經歷了幾乎所有關於這一主題在這裏的問題了但他們沒有解決我的問題
下面是實體類
@Entity
public class UserDetails {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID")
int id;
@Column(name="NAME")
String name;
@Column(name="ADDRESS")
String address;
@ElementCollection(targetClass=String.class)
@CollectionTable(name="HOBBIES",[email protected](name="ID"))
@Column(name="HOBBIES")
List<String> hobbies;
@Column(name="INTEREST")
String interest;
下面是相關的日誌信息
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, for columns: [org.hibernate.mapping.Column(HOBBIES)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:410)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1099)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1284)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 82 more
由於我無法精確定位庫中的jpa版本,我正在共享我的pom.xml
。
下面是我目前pom.xml
爲hibernate
<!-- Hibernate resources -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
我在最後添加下面嘗試
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
我已經改變了hibernate-entitymanager
版本從3.6.7.Final
到5.1.0.Final
,既沒有工作。
您正在使用哪種jpa/hibernate版本?並共享ElementCollection的導入庫 –
@KhalilM我已更新問題 –
我在本地機器上運行了你的代碼,它的工作正常!我正在使用'hibernate-core:5.0.11','hibernate-entitymanager:5.0.11'和'hibernate-jpa-2.1-api' v'1.1.0 Final'。 –