-->
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.  [ 6 posts ] 
Author Message
 Post subject: Version attribute not refreshed in my Object
PostPosted: Wed Feb 18, 2009 6:31 am 
Beginner
Beginner

Joined: Tue Dec 19, 2006 12:55 pm
Posts: 27
Hi all,

I have an object with a version attribute, i have also a version tag in my hbm mapping file. If i run the code:


Code:

AObj someObj= // already populated before;

AObj merged= (AObj) session.merge(someObj);
session.saveOrUpdate(merged);
session.flush();



The version column is updated correctly in my table, but not in my "someObj" object, so i'm forced to add this line in order to get my object updated.

Code:
BeanUtils.copyProperties(merged, someObj);


Is this the right solution for this issue?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 12:41 pm 
Beginner
Beginner

Joined: Tue Dec 19, 2006 12:55 pm
Posts: 27
Hi again, any response for this question? Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 1:05 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Why don't you just do something like:
Code:
someObj= // already populated before;

someObj= (AObj) session.merge(someObj);


Is it because you want to keep references to this object? In that case try session.refresh(someObj) after you have flushed the session.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 1:05 pm 
Newbie

Joined: Fri Feb 13, 2009 1:46 pm
Posts: 9
I'm not sure I understand your question. Are you saying that "merged" is not having it's version updated? "someObj" should not be used again after calling session.merge(). "someObj" is never associated with the session, and will not have it's version updated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 5:21 am 
Beginner
Beginner

Joined: Tue Dec 19, 2006 12:55 pm
Posts: 27
So after saveOrUpdate, i should forget "someObj" and start working with the "merged" object instead, isn't it?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 5:41 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Yes, merge returns a merged instance of your entity, it does not reattach the current object, it copies it's state to a managed instance.

Notice that the version number is not incremented immediately after calling merge(), because on session.merge() the state of the object is not flushed to the database, so the version number is not incremented.
The number is updated after flushing the session.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.