-->
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.  [ 2 posts ] 
Author Message
 Post subject: using HQL and opportunistic locking/versioning
PostPosted: Mon Mar 16, 2009 5:15 pm 
Newbie

Joined: Mon Mar 16, 2009 5:04 pm
Posts: 2
I'm a hibernate newbie and I have a question regarding direct HQL queries/inserts and versioning. I've been searching the web for anything related to this, but I can't seem to find anything that addresses this question.

I know that if I interact with hibernate using objects, that hibernate under the hoods will version things for me, and be able to detect if there was an update on the same row that I am currently updating. This is accomplished by hibernate checking the version column to see if the version number was incremented.

However, what about the case where I'm using a direct HQL query? For example, instead of something like

Transaction t = session.beginTransaction();
foo.setProperty("bar");
session.flush();
t.commit();
session.close();

what if instead I issued an HQL command something like

update foo set property='bar';

Instead of interacting with the actual object, I"m just basically updating the column in the database. Will hibernate still do the versioning automatically still, or will I need to implement this myself? If I need to implement this myself, will I need to use pessimistic locking, or can I still somehow use optimistic locking?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 17, 2009 7:47 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Hibernate will, by default, not update versions or timestamps. According to the documentation at http://www.hibernate.org/hib_docs/v3/re ... irect.html
you should be able to do

Code:
update versioned foo set property='bar'

to force Hibernate to also update the version or timestamp.


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