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.  [ 3 posts ] 
Author Message
 Post subject: Persisting multiple mapped class in one transaction (bug?)
PostPosted: Mon Dec 08, 2008 6:41 am 
Newbie

Joined: Thu Sep 27, 2007 1:15 am
Posts: 3
Location: Amsterdam
Hi all,

I've mapped a class to multiple tables, similar to the example from the hibernate documentation (http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping-entityname.html).

However when an object is persisted to each mapping-entity in one transaction (in the example, to both the CurrentContract and HistoricalContract table),
the first persist is successful, but the second is not.

Probably because the object is already in the session for the first insert, Hibernate can't register it again in the session for the second insert.

I have a workaround in using persist and then evict for the first persist, but this is not ideal.

Is this a known bug?

Thanks and regards,

Lennard.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2008 6:55 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
They way you describe it I don't think it is a bug. A single object instance can only have ONE identity. If you have done like the example in the link you posted you would need TWO different objects if you want both in the same session at the same time. One for the CurrentContract and one for the HistoricalContract.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2008 7:33 am 
Newbie

Joined: Thu Sep 27, 2007 1:15 am
Posts: 3
Location: Amsterdam
nordborg wrote:
They way you describe it I don't think it is a bug. A single object instance can only have ONE identity. If you have done like the example in the link you posted you would need TWO different objects if you want both in the same session at the same time. One for the CurrentContract and one for the HistoricalContract.


Hmm, wouldn't it be a valid use case to be able to persist the object to multiple tables in one go, one for the actual Contract, and one for the change history of the contract?

I agree with you that object identity is an important concept in this respect, since Hibernate uses this to flush any changes of the object during transaction completion. However this should not mean you'd have to create a deep copy of the object if you'd like to persists the object to the a second table, which is very error prone when its a large object (or in our case a large object tree!).

Anyway, thanks for clearing this up.

Regards,

Lennard.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.