Я пытаюсь сопоставить существующую базу данных Oracle с классами 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. Меттеры-геттеры и конструкторы были удалены, чтобы сократить его.
@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, он работал.