我正在尝试将现有的Oracle DB映射到JPA类。但是我在主题行中遇到了提到的错误。无法找出真正的问题。也许我将实体映射错误。
已经尝试过更改类的定义方式。还尝试了在PostgreSQL上正常工作的方法。
CREATE TABLE "JDTA_ITEM_MULTI_ATTRS"
( "JDTA_ITEM_ID" NUMBER(*,0) NOT NULL ENABLE,
"ATTR_DATA_VALUE_ID" NUMBER(*,0) NOT NULL ENABLE,
"ATTR_DATA_TYPE_ID" NUMBER(*,0) NOT NULL ENABLE,
CONSTRAINT "JDTA_ITEM_MULTI_ATTRS_PK" PRIMARY KEY ("JDTA_ITEM_ID", "ATTR_DATA_VALUE_ID"))
CREATE TABLE "ATTR_DATA_KSATRS"
( "ATTR_DATA_VALUE_ID" NUMBER(*,0) NOT NULL ENABLE,
"KSATR_TYPE_ID" NUMBER(*,0) NOT NULL ENABLE,
CONSTRAINT "ATTR_DATA_KSATRS_PK" PRIMARY KEY ("ATTR_DATA_VALUE_ID"))
CREATE TABLE "DVMHR4W"."ATTR_DATA_RESOURCES"
( "ATTR_DATA_VALUE_ID" NUMBER(*,0) NOT NULL ENABLE,
"ATTR_DATA_RESOURCE_TYPE_ID" NUMBER(*,0) NOT NULL ENABLE,
"PART_NUMBER" VARCHAR2(150 BYTE),
"SRC" VARCHAR2(300 BYTE),
CONSTRAINT "ATTR_DATA_RESOURCES_PK" PRIMARY KEY ("ATTR_DATA_VALUE_ID"))
下面是Java实体类。为了使内容简短,已删除了Getter setter和Constructor。
@Entity
@IdClass(JdtaItemMultiAttrsPk.class)
@Table(name = "JDTA_ITEM_MULTI_ATTRS")
@Inheritance(strategy = InheritanceType.JOINED)
public class JdtaItemMultiAttrs
implements Serializable
{
/**
* generated id
*/
private static final long serialVersionUID = 8002L;
@Id
@Column(name = "jdta_item_id")
private int jdtaItemId;
@Id
@Column(name = "attr_data_value_id")
private int attributeDataValueId;
@OneToOne
@JoinColumn(name = "attr_data_value_id", insertable = false, updatable = false)
private AttributeDataValue attributeDataValue;
@Column(name = "attr_data_type_id")
private int attributeDataTypeId;
}
public class JdtaItemMultiAttrsPk
implements Serializable
{
/**
* generated id
*/
private static final long serialVersionUID = 8002L;
private int jdtaItemId;
private int attributeDataValueId;
}
@Entity
@Table(name = "ATTR_DATA_RESOURCES")
@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name = "attr_data_value_id")
, @PrimaryKeyJoinColumn(name = "jdta_item_id")})
public class AttrDataResource extends JdtaItemMultiAttrs
implements Serializable
{
/**
* generated id
*/
private static final long serialVersionUID = 1600L;
@Column(name = "attr_data_value_id",insertable = false, updatable = false)
private int id;
@Column(name = "attr_data_resource_type_id")
private int attrDataResourceTypeId;
@OneToOne
@JoinColumn(name = "attr_data_resource_type_id",insertable = false, updatable = false)
private AttrDataResourceType attrDataResourceType;
@OneToOne
@JoinColumn(name = "attr_data_value_id", insertable = false, updatable = false)
private AttributeDataValue attributeDataValue;
@Column(name = "part_number")
private String partNumber;
@Column(name = "src")
private String source;
}
@Entity
@Table(name = "ATTR_DATA_KSATRS")
@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name = "attr_data_value_id")
, @PrimaryKeyJoinColumn(name = "jdta_item_id")})
public class AttributeDataKsatr extends JdtaItemMultiAttrs
implements Serializable
{
/**
* generated id
*/
private static final long serialVersionUID = 1L;
@Column(name = "attr_data_value_id",insertable = false, updatable = false)
private int id;
@OneToOne
@JoinColumn(name = "ksatr_type_id")
private KsatrType type;
@OneToOne
@JoinColumn(name = "attr_data_value_id", insertable = false, updatable = false)
private AttributeDataValue attributeDataValue;
}
这是我运行此错误
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.JoinedSubclassEntityPersister
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:402) ~[spring-orm-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
... 16 common frames omitted
Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.JoinedSubclassEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:112) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:154) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.7.RELEASE.jar:5.1.7.RELEASE]
... 20 common frames omitted
Caused by: java.util.NoSuchElementException: null
at java.util.ArrayList$Itr.next(ArrayList.java:854) ~[na:1.8.0_144]
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:301) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_144]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_144]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_144]
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]
... 28 common frames omitted
需要在此处查找导致问题的确切原因。我正在使用Spring Boot 2.1.5和Hibernate 5.3.9 / 11,Oracle DB。
当我尝试在PostgreSQL中复制相同的场景时,它起作用了。