-->
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: Overriding the value of the version number
PostPosted: Tue Aug 24, 2004 1:42 am 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Hibernate version: 2.1.2

We are using the "Many sessions with automatic versioning" approach on our application (section 17.3.2.).
We have a brand new Hibernate Session for each service layer request and we use DTOs to communicate across the service boundary (ie. the client never sees the domain objects).

I think I have seriously misunderstood what we could do with this functionality, but I'd like to double-check that I'm not simply doing something wrong.

Versioning is working fine, and I believe that ordinary optimistic locking is working fine.

The problem is, I want to override the version number on a particular instance (setting it to a specific, possibly older number) and have hibernate detect (by issuing the update statement with the given version number in the where clause) if the version of the object is stale.

I wanted to do this:
Code:
Domain domain = session.load(Domain.class, dto.getId());
domain.setSomeValue( dto.getSomeValue() );
domain.setVersion( dto.getVersion() );

session.commit();

And have hibernate throw an exception during the commit call if the version number in the DB had moved on from the version number I set.

According to my debugger, the part where I call domain.setVersion() works fine. But inside the call to session.commit(), the domain.version attribute just gets set to whatever the version in the DB is (regardless of how far in advance it is to the number my code set in the version attribute) + 1.

So, hibernate appears not to look at the version I set onto the domain object, it just overwrites it, yes?

I know I can do my own version checking in application code, I just was under the impression that hibernate would do that for me.

So, I guess the question is: hibernate won't do the version check for me if I override the version number on the domain object, will it?

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject: a solution.
PostPosted: Tue Oct 05, 2004 7:08 pm 
Newbie

Joined: Tue Oct 05, 2004 5:28 pm
Posts: 3
Location: san francisco, ca
Found it here. Calling Session.evict(theObj) before Session.update(theObj) did make things work.
http://forum.hibernate.org/viewtopic.ph ... setversion

thanks...
Hernan


Top
 Profile  
 
 Post subject: anyone from Hibernate care to comment?
PostPosted: Fri Apr 15, 2005 4:36 pm 
Newbie

Joined: Tue Mar 08, 2005 11:58 am
Posts: 2
I have exactly the same issue. I made the following post to JIRI:

http://opensource.atlassian.com/project ... se/HHH-348

Note Gavin's self-absorbed, obnoxious comment.

In any case, it doesn't matter if Hibernate allows updating of the version property or not - but they should at least support and document a method for supporting this model ie, data communication between client and service via DTOs rather than the actual Java POJO.

Manually checking checking versions or using evict/update seems like a hack IMO.


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.