-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: JOINED Inheritance with circular reference
PostPosted: Tue Apr 04, 2017 12:40 pm 
Newbie

Joined: Tue Apr 04, 2017 11:45 am
Posts: 3
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.


Top
 Profile  
 
 Post subject: Re: JOINED Inheritance with circular reference
PostPosted: Wed Apr 05, 2017 1:12 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I think this is an issue. You need to write a replicating test case and open a new Jira issue.


Top
 Profile  
 
 Post subject: Re: JOINED Inheritance with circular reference
PostPosted: Wed Apr 05, 2017 5:14 am 
Newbie

Joined: Tue Apr 04, 2017 11:45 am
Posts: 3
Hello, I've found the issue. It's not an Hibernate issue but it was in my entity.
In the base class entity I had a misprint due to the automatic generation which put the @One2One reference to TableB

Code:
@OneToOne(fetch = FetchType.LAZY, mappedBy = "parent")
public TableB getTableB() {
    return this.tableB;
}


I removed such property and now it works.
Anyway this thread could be useful for the future, especially for people who use Hibernate Tools for Entities generation.
Many thanks for your support


Top
 Profile  
 
 Post subject: Re: JOINED Inheritance with circular reference
PostPosted: Wed Apr 05, 2017 5:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Thanks for providing the answer to your question. I'm glad it works now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.