-->
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: foreign key issue in one transaction, please help
PostPosted: Tue Jul 15, 2008 11:05 pm 
Newbie

Joined: Sun Jun 22, 2008 10:08 pm
Posts: 4
Hey guys,

I'm having problem getting the scenario below working in one transaction.

Assume:
Table #1 - "salesTable"
Table #2 - "salesHistory"

salesTable has the following composite ID (customerId, salesId)
note# customerId is known before hand, salesId is generated (+1) during each insert.

salesHistory has the same composite ID (customerId, salesId)
I need the salesId in the salesHistory to be the same as the salesTable's salesId.

How can I do that in one transaction, so that the salesHistory's saleId can get the generated id from the salesTable?

thx so much,
George


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 16, 2008 6:11 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Could you just get the id from the save() method? The save method returns the primary key used by the entity. Then set it in the other object, all within a single Hibernate Session. Possible?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.