-->
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.  [ 2 posts ] 
Author Message
 Post subject: Single Entity Mapped to Multiple Tables
PostPosted: Tue Jun 07, 2011 9:27 am 
Newbie

Joined: Wed Feb 23, 2011 6:23 pm
Posts: 5
Hi All

I am trying use the Single Entity Mapped to Multiple Tables . I have two tables Order and OrderHistory. Order is given the entity-name ''OrderObj'' and ''OrderHist'' respectively

when the
HibernateUtil.beginTransaction()
getSession().save(''OrderObj'',order) and
getSession().save(''OrderHist'',order)
HibernateUtil.commitTransaction()

are called within the same transaction only
OrderObj is saved and not OrderHist

but if they are saved by starting different transactions both of them are saved .
HibernateUtil.beginTransaction()
getSession().save(''OrderObj'',order)
HibernateUtil.commitTransaction()

HibernateUtil.beginTransaction()
getSession().save(''OrderHist'',order)
HibernateUtil.commitTransaction()

what may be the issue.

Both the tables have the same columns names except one extra column in OrderHist

Please advise


Top
 Profile  
 
 Post subject: Re: Single Entity Mapped to Multiple Tables
PostPosted: Tue Jun 07, 2011 4:48 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Inside a single Hibernate session each object must be unique, so you can't use the same 'order' instance to represent two different entities. In the first code example, I guess Hibernate simply ignores the second call to save() since the object has already been saved. To get this to work you need to clone the 'order' object.

The reason that the second code example works is probably hidden in the HibernateUtil.beginTransaction(). If this creates a new session or clears the old session then I guess it is valid to re-save the same instance with a different entity-name.


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