-->
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.  [ 4 posts ] 
Author Message
 Post subject: Revisit - Many sessions with automatic versioning
PostPosted: Thu Sep 23, 2004 9:45 am 
Newbie

Joined: Wed Mar 03, 2004 2:57 pm
Posts: 4
I have the same issue as below, and seem no one provided an answer, I have the exact same situation. Basically, even i hardcod the setting of the version number to the object it seems that hibernate reads from the DB and i can see the call to <engine.Versioning.increment from value(read from DB to new incremeneted value)>

Any idea?

Thanks,
Hadi

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: 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.



Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: Revisit - Many sessions with automatic versioning
PostPosted: Thu Sep 23, 2004 9:48 am 
Newbie

Joined: Wed Mar 03, 2004 2:57 pm
Posts: 4
BTW, I tried to intercept the version property via an Intercepter and change it to some number but still with no luck.


Top
 Profile  
 
 Post subject: I'm having this problem too...
PostPosted: Tue Oct 05, 2004 5:42 pm 
Newbie

Joined: Tue Oct 05, 2004 5:28 pm
Posts: 3
Location: san francisco, ca
Seems like a few of us now. Please post if you got any offline responses to this issue.
thanks...
hernan


Top
 Profile  
 
 Post subject: a solution.
PostPosted: Tue Oct 05, 2004 7:07 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  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.