-->
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.  [ 5 posts ] 
Author Message
 Post subject: Optimistic Lock: How to get back the new version?
PostPosted: Thu Nov 29, 2007 9:23 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
Hi,

I have an application where a Java Swing Client can do several updates on an object graph of entities. All entities have an optimistic locking version number. So, when i do an update on the server, I want to return to the client new version of each updatet entity. I thought that simply flushing the transaction and re-reading the object would do the thing. But i only get back the old version.

My code looks like this:

public Institution updateInstitution(final Institution pInstitut) {
Institution iold = dao.findById(pInstitut.getId(), true);


dao.getEntityManager().merge(pInstitut);
dao.getEntityManager().flush();

Institution inew = dao.findById(pInstitut.getId(), false);
inew.getContact();
return inew;
}

In the case where I do my tests I just change an attribute of the Contact entity. And this is exactly where Hibernate creates an Update statement. The problem here is: I don't get the new version of the updated Contact object.

Any suggestions please?

Carlo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 11:52 am 
Newbie

Joined: Thu Nov 29, 2007 11:49 am
Posts: 7
I have a issue something like that. I am new to hibernate and I was invovled in upgrading to a newer version of hibernate ie3.2.5. Since the upgrade whenever any fiels is updated the a older version of the field is diplayed. This was not an issue with the prior version of hibernate.

Any thoughts

_________________
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 02, 2007 8:59 am 
Beginner
Beginner

Joined: Tue Nov 27, 2007 9:44 am
Posts: 46
If I understand your problem correctly, you change an attribute of the Contact entity which means, you do not change the Institution entity at all.

So, why should it create a new Version of the Institution entity in question?

Regards,
Frank


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 03, 2007 4:25 am 
Newbie

Joined: Sat Nov 27, 2004 8:39 am
Posts: 3
AlmGhandi wrote:
If I understand your problem correctly, you change an attribute of the Contact entity which means, you do not change the Institution entity at all.

So, why should it create a new Version of the Institution entity in question?

Regards,
Frank


I just wanted to make life easier -:). Institution is the root object of these business entities; it has a Contact, and a Contact has Addresses. As the client always needs these objects together, the associations are marked for cascading.
So, the nice feature is, I can just say 'UpdateInstitution' and Hibernate does the rest. In my example it detects that just Contact needs this update.

Then, by returning an Institution object, I really return the whole updated object graph (for further changes).

So, my problem is of course: for each object which was updated, I need the new object version.

BTW: my entities have this attribute:
@Version @Column(name = "OBJ_VERSION")
private int version = 0;

Carlo

_________________
Carlo Luib-Finetti
Berlin/Germany


Top
 Profile  
 
 Post subject: Problem solved
PostPosted: Mon Dec 03, 2007 11:05 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
Shame on me! I was TOO consternated by the problems reported - and as I saw now: produced - by the client that I didn't see that on the server side everything worked just fine. Hibernate and Entity Manager work as expected.

Sorry for this false alarm / noise!

Carlo


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