-->
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.  [ 1 post ] 
Author Message
 Post subject: Associated Object Persistence problem
PostPosted: Tue Jul 27, 2010 8:18 pm 
Newbie

Joined: Tue Jul 27, 2010 7:51 pm
Posts: 3
I am relatively new to hibernate, hence my apologies if the question turns out to be a dumb one...

I am trying to persist data in a following scenario:

Here is some background information:

TableObject1 <TO1>: is a pure table which hold new data

TableObject2 <TO2>: is a relationship table with Foreign Key pointing to <TO1>

A sample illustration of code is:

TO1 : Property1, Property2, Set <TO2> setTO2

TO2 : PK1, Property1, TO1



Now, initially using session.save(TO1 instanceTO1). I am able to persist the instanceTO1 data in to the corresponding table <TO1>.

Now I want to persist TO2 data into database table <TO2>. But the approach I am taking is to populate TO2 using instanceTO1.setTO2 property of TO1 class. So the property setTO2 of TO1 has a multiple TO2 items which would technically be insert statements into Database.

Problem: After I persist TO1 without populating setTO2 property, it updates table <TO1> in DB. Now, since hibernate checks for the changes in a persisted state object i.e. instanceTO1 of TO1 here. I expect it to do inserts into TO2 because I populate setTO2 property of TO1 after I persist it and this can happen at some point later. This is not happening when I am trying it out. Where am I going wrong?? session.saveOrUpdate(instanceTO1) does the inserts after i update it with TO2 sets. But I want to know the handling mechanism of hibernate and hence this question.


Thanks once again for answering my question in advance.


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

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.