-->
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: Experiencing difficulties with inheritance + composite ID
PostPosted: Mon Aug 27, 2007 9:16 am 
Beginner
Beginner

Joined: Mon Aug 27, 2007 8:10 am
Posts: 37
Yes, I know, composite ids are out of favor here, however we have strong design reasons to use composite ids, so we do.

Now we stuck with a hibernate error, and the behavior we are observing looks like a bug.

We have a root class R and its subclass S on a single table inheritance.
R has fields OID and CID as the primary key, CID is also used as discriminator column.

R has collection of classes L, which have two Many-To-One association to R - left and right. Instances of L we use to model attributed Many-Many-To-Many association R<->R.

In our basic test we managed to create new and get existing instances of R and S.
We also succeeded with creating an association L between a new instance of R and an existing instance of R.
However, on creating association new R <-> existing S, we are getting error:

Code:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.entity.L.right -> com.entity.R


We have debugged hibernate and found that exception is thrown in CascadingAction.java:~353 because ForeignKeys.isTransient returns true. This happens because in AbstractEntityPersister.java:~3305 function canExtractIdOutOfEntity() returns false.
We found what is the difference between runs R<->R and R<->S: for the first case hasIdentifierMapper() (AbstractEntityPersister.java:~3410) returns true, while for the second – false.
In the debugger, we have changed hasIdentifierMapper for class S to true and test has succeeded and was working well until we redeploy our application.

We have debugged further and found that this property (hasIdentifierMapper) is set from value got from the Metamodel (PersistentClass:~758)

Code:
public boolean hasIdentifierMapper() {
return identifierMapper != null;
}


In our opinion, this method should be overridden in Subclass (or SingleTableSubclass) as the following:
Code:
public boolean hasIdentifierMapper() {
return superclass.hasIdentifierMapper();
}


What we need is a quick workaround which does not require changes in hibernate sources.
Setting AbstractEntityPersister.hasIdentifierMapper to true would work for us, unfortunately we do not know how to get access to the instance of AbstractEntityPersister corresponding to our class (S) and what is proper context of doing this fix.

Thank you for reading to this point ;)


Top
 Profile  
 
 Post subject: Similar bug for composite ID is reported as fixed
PostPosted: Tue Aug 28, 2007 4:07 am 
Beginner
Beginner

Joined: Mon Aug 27, 2007 8:10 am
Posts: 37
I am rasing up this issue again. There is a bug in JIRA, which reported as fixed in 3.1.3, however, we see this problem in 3.2.4.sp1

http://opensource.atlassian.com/project ... e/HHH-1489


Top
 Profile  
 
 Post subject: Re: Experiencing difficulties with inheritance + composite I
PostPosted: Tue Aug 28, 2007 6:15 am 
Regular
Regular

Joined: Thu Oct 19, 2006 12:07 pm
Posts: 75
hutorny wrote:
Setting AbstractEntityPersister.hasIdentifierMapper to true would work for us, unfortunately we do not know how to get access to the instance of AbstractEntityPersister corresponding to our class (S) and what is proper context of doing this fix.


You can get the AbstractEntityPersister like this (at least that is how I do it) :

Code:
ClassMetadata meta = yourSessionFactory.getClassMetadata(S.class);

if (meta instanceof AbstractEntityPersister) {
    AbstractEntityPersister enPer = (AbstractEntityPersister) meta;
}


Regards,
David

PS: Notice how credit-starved I am ;-)


Top
 Profile  
 
 Post subject: Re: Experiencing difficulties with inheritance + composite I
PostPosted: Tue Aug 28, 2007 9:13 am 
Beginner
Beginner

Joined: Mon Aug 27, 2007 8:10 am
Posts: 37
xerces8 wrote:
You can get the AbstractEntityPersister like this (at least that is how I do it) :

Code:
ClassMetadata meta = yourSessionFactory.getClassMetadata(S.class);

if (meta instanceof AbstractEntityPersister) {
    AbstractEntityPersister enPer = (AbstractEntityPersister) meta;
}


Regards,
David


Thanks, David, this really helps. The way we found is much longer.


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.