-->
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: Does a commit save a transaction
PostPosted: Wed Apr 07, 2010 11:30 am 
Newbie

Joined: Wed Apr 07, 2010 11:10 am
Posts: 2
I'm now in charged of the following code and I 'm not sure if I correctly understand what the guy was doing ..
void methodA(){
sess=SessionFactory.openSession();
tx=sess.beginTransaction(),;

myobj1 = sess.get(MyObj1.class , anInt),
myobj2 = myobj1.cloneDeep();
sess.save(myobj2) ;

myobj1.setAttrib1(newvalue);
myobj1.setAttrib2(newvalue);

tx.commit();
sess.close();
}

myobj1 and 2 are local vars not instVar. What happens here ??

I understand that myobj2 will be newly saved and thus gets a new id in the table (a new row in the table) but what happens with myobj1 does the commit flush the in-memory cache and also save myobj1 thus actually executing an update on the DB of myobj1 ?? Or will the newly assigned values to myobj1 be discarded when method end since myobj1 is locally declared ??

thanks for your help
nitro


Top
 Profile  
 
 Post subject: Re: Does a commit save a transaction
PostPosted: Thu Apr 08, 2010 2:56 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
myobj1 is still loaded in the persistent context when you set Attrib1 and Attrib2 (it doesn't matter if the myobj1 is declared local or something else), so this changes are tracked and propagated to the database when you flush or commit (unless you deactivated auto-flush on commit).


Top
 Profile  
 
 Post subject: Re: Does a commit save a transaction
PostPosted: Thu Apr 08, 2010 6:04 pm 
Newbie

Joined: Wed Apr 07, 2010 11:10 am
Posts: 2
many thanks pb00067 the missing element for me was this auto-flush on the commit. I will check that. thanks ..


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.