java - @ElementCollection 用于映射 Object 类的列表

标签 java hibernate

喂,,

我使用@ElementCollection 来映射对象类列表,但我遇到了消息问题:

java.lang.ExceptionInInitializerError
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean     with name 'ObjWellSvc': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.prosia.wmls.service.repo.ObjWellRepo com.prosia.wmls.service.impl.ObjWellSvcImpl.objWellRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ObjWellRepo': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.hibernate.SessionFactory com.prosia.wmls.service.repo.impl.BaseImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/D:/NetBeansProjects/WITSML%20(Energistic)/WitsServer/src/java/cfg/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: collection element mapping has wrong number of columns: com.prosia.witsml.dataobject.CsCustomData.any type: object
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.prosia.wmls.service.TesterClass.<clinit>(TesterClass.java:19)

这是字段的声明:

@ElementCollection
@CollectionTable(name="any", joinColumns=@JoinColumn(name="customdataID"))
@Column(name="any_")
protected List<Object> any;

所以任何人都可以帮助我...解决这个问题...

谢谢

最佳答案

您尝试持久化 java.lang.Object 的任意实例。根据 JPA 2.0,支持以下类型:

The persistent fields or properties of an entity may be of the following types: Java primitive types; java.lang.String; other Java serializable types (including wrappers of the primitive types, java.math.BigInteger,java.math.BigDecimal,java.util.Date, java.util.Calendar[5], java.sql.Date, java.sql.Time, java.sql.Timestamp, byte[], Byte[], char[], Character[], and user-defined types that implement the Serializable interface); enums; entity types; collections of entity types; embeddable classes (see Section2.5); collections of basic and embeddable types (see Section 2.6).

关于java - @ElementCollection 用于映射 Object 类的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11358567/

相关文章:

java - 无法访问 Android 的 Java Keystore

java - Scala 是函数式编程语言吗?

Java Spring - 使用 API 持久化对象可以工作,但我无法在测试中使用服务持久化对象,空指针

java - Hibernate 写入后读取导致找不到对象

java - Spring @Transactional 即使抛出异常也会提交部分结果

java - Hibernate:带有继承的 NaturalId

java - 使用 Hibernate 的对象关系映射 - "Sessionbound"是什么意思?

java - 如何在eclipse中查找类路径中的文件

java - 视频文件转换/转码 Google App Engine

java - 使 JavaFX 应用程序非静态