Hello, I have a problem using inheritance and Hibernate.
This is my situation.
I have two tables: TABLE_A and TABLE_B.
TABLE_B has a FK to
TABLE_A and
TABLE_A has a FK to itself.
I mapped the following two entities:
Code:
package eu.europa.ec.dgnear.mis.converter;
@Entity
@Table(name = "TABLE_A")
@Inheritance(strategy=InheritanceType.JOINED)
public class TableA {
@Id
@Column(name = "ID", unique = true, nullable = false)
private id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PARENT_ID")
private TableA parent;
{....}
}
Code:
@Entity
@Table(name = "TABLE_B")
public class TableB extends TableA{
{....}
}
The TableB entity has the same ID name of TableA so I didn't put the
@PrimaryKeyJoinColumn annotation.
Now, when I start the server I have the following error:
Code:
Caused By: org.hibernate.MappingException: property [parent] not found on entity [TableB]
at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:442)
at org.hibernate.mapping.PersistentClass.getReferencedProperty(PersistentClass.java:382)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1724)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
at weblogic.persistence.BasePersistenceUnitInfo.initializeEntityManagerFactory(BasePersistenceUnitInfo.java:611)
at weblogic.persistence.BasePersistenceUnitInfo.init(BasePersistenceUnitInfo.java:199)
at weblogic.persistence.BaseJPAIntegrationProvider.createPersistenceUnitInfo(BaseJPAIntegrationProvider.java:54)
at weblogic.persistence.AbstractPersistenceUnitRegistry.storeDescriptors(AbstractPersistenceUnitRegistry.java:422)
at weblogic.persistence.AbstractPersistenceUnitRegistry.loadPersistenceDescriptors(AbstractPersistenceUnitRegistry.java:128)
at weblogic.persistence.ModulePersistenceUnitRegistry.<init>(ModulePersistenceUnitRegistry.java:56)
that's already strange since TableB extends TableA.
Anyway if I add an override of getParent() property in TableB, the server starts up well but, when I try to make a select, Hibernate tries to put the parent field to the TABLE_B table, that's not correct (
SELECT TABL0_.parent.....FROM TABLE_B).
I tried to put @Transient in the TableB getParent() property but I run to the previous error again.
Where is my mistake?
Thank you in advance for your support
PS
I had to rename the tables to fake names for NDA reasons. So forgive me if I did some mistake on reproducing the example code.