我确实有一个实体Root
@Entity
public class Root {
@Id
String id;
@ElementCollection
@CollectionTable
List<Col> cols ;
收集物品&#39; Col&#39;有一个嵌入对象本身
@Embeddable
public class Col {
@Embedded
private Emb emb;
&#39; Emb&#39;对象非常简单
@Embeddable
public class Emb {
String embField;
我希望数据库表就像那样
表:ROOT 字段:ID
表:ROOT_COLS 字段:ROOT_ID,EMB_FIELD
启动这个Spring Boot应用程序会给我一个ArrayIndexOutOfBoundsException
如何解决此问题?
hibernate版本:5.0.12
org.springframework.beans.factory.BeanCreationException:创建名称为&#39; entityManagerFactory&#39;的bean时出错在类路径资源中定义[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]:调用init方法失败;嵌套异常是javax.persistence.PersistenceException:[PersistenceUnit:default]无法构建Hibernate SessionFactory 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)〜[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)〜[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)〜[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)〜[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)〜[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)〜[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)〜[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)〜[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)〜[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)〜[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)〜[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:314)[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 在ch.admin.estv.map.Application.main(Application.java:33)[classes /:na] 引起:javax.persistence.PersistenceException:[PersistenceUnit:default]无法构建Hibernate SessionFactory 在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)〜[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final] 在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882)〜[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final] 在org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)〜[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)〜[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)〜[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)〜[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)〜[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)〜[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] ...省略了16个常用帧 引起:org.hibernate.MappingException:无法实例化集合persister org.hibernate.persister.collection.BasicCollectionPersister 在org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:167)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 在org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:140)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 在org.hibernate.internal.SessionFactoryImpl。(SessionFactoryImpl.java:399)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 在org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)〜[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final] ...省略了22个常用帧 引起:java.lang.ArrayIndexOutOfBoundsException:1 在org.hibernate.persister.collection.AbstractCollectionPersister.initCollectionPropertyMap(AbstractCollectionPersister.java:1914)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 在org.hibernate.persister.collection.AbstractCollectionPersister.initCollectionPropertyMap(AbstractCollectionPersister.java:1891)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 在org.hibernate.persister.collection.AbstractCollectionPersister。(AbstractCollectionPersister.java:592)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 在org.hibernate.persister.collection.BasicCollectionPersister。(BasicCollectionPersister.java:57)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)〜[na:1.8.0_121] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)〜[na:1.8.0_121] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)〜[na:1.8.0_121] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)〜[na:1.8.0_121] 在org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:152)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] ...省略了26个常见帧
答案 0 :(得分:3)
问题是实体的默认访问权限是字段,但对于嵌入对象,默认访问权限是属性。
所以Col类应该是
@Embeddable
@Access(AccessType.FIELD)
public class Col {
@Embedded
private Emb emb;
和Emb类
@Embeddable
@Access(AccessType.FIELD)
public class Emb {
String embField;
我会喜欢更好的错误消息然后是ArrayIndexOutOfBoundsException!