-->
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: Update with the Criteria API
PostPosted: Mon Sep 25, 2006 8:17 pm 
Newbie

Joined: Thu Aug 17, 2006 10:18 am
Posts: 9
We have an app in which we need to lock a set of rows in the database and then perform a look up. I'm aware of using an update sql statement to do this but I was looking for an object oriented way of performing the same and like if I need to do something like

update <table_name> set lockId=2 where ownerQId=<name>

how do I express this in an object oriented fashion using Hibernate ?

I tried to use the criteria API to to replace the where clause but looks like the Query interface does not take any criteria object, so there is no way of doing something like

session.createQuery("update <table_name> set lockId=2).add(Expression.eq("ownerQId", <name>))

Did anyone come across something anything similar to this before ? can you share your thoughts ? Appreciate all the responses.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 9:50 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That's not possible. There's no OO way of doing that, because there are no objects involved. The most hibernate-y way of doing it is to use HQL's DML facilities. See section 13.4 of the ref docs.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: Re: Update with the Criteria API
PostPosted: Tue Sep 26, 2006 2:47 am 
Newbie

Joined: Mon Sep 25, 2006 7:42 am
Posts: 7
No We cannot achieve this using hibernate 3.0, may be hibernate team may consider these kind of expections future versions

vin wrote:
We have an app in which we need to lock a set of rows in the database and then perform a look up. I'm aware of using an update sql statement to do this but I was looking for an object oriented way of performing the same and like if I need to do something like

update <table_name> set lockId=2 where ownerQId=<name>

how do I express this in an object oriented fashion using Hibernate ?

I tried to use the criteria API to to replace the where clause but looks like the Query interface does not take any criteria object, so there is no way of doing something like

session.createQuery("update <table_name> set lockId=2).add(Expression.eq("ownerQId", <name>))

Did anyone come across something anything similar to this before ? can you share your thoughts ? Appreciate all the responses.

_________________
Never Give Up


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 5:48 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
use

seesion.createQuery("update <table_name> set lockId=2 where ownerQId=<name>").executeUpdate()

in order to execute this using HQL

this shall give you no of rows updated using above query




Sudhir


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.