-->
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: HQL - complex update query
PostPosted: Wed Sep 24, 2008 11:37 am 
Newbie

Joined: Thu Sep 18, 2008 7:39 am
Posts: 6
Hi,

I've got problem to exceute one update-HQL-query.

There tree tables:

Code:

CRAETE TABLE CATEGORY_GROUP (
   CATEGORY_GROUP_ID,
   NAME
)

CRAETE TABLE PARAMETER_CATEGORY (
   PARAMETER_CATEGORY_ID,
   NAME,
   CATEGORY_GROUP_ID
     REFERENCES( CATEGORY_GROUP .CATEGORY_GROUP_ID )
)


CRAETE TABLE PARAMETER (
   PARAMETER_ID,
   NAME,
   VALUE,
   PARAMETER_CATEGORY_ID,
     REFERENCES( PARAMETER_CATEGORY.PARAMETER_CATEGORY_ID, )
)



I want to execute the following update query:

Code:
session.createQuery("UPDATE Parameter  p SET p.desc = ? " +
     "WHERE p.category.categoryGroup.name = ? ")
     .setParameter(0, "updated_value")
     .setParameter(1, "group_name").executeUpdate();


The hibernate generates sql query like this:
Code:
Hibernate: update PARAMETER,  set VALUE=? where NAME=?

which is obviously wrong. Is it possibe to execute somehow update like this or hibernate does not have this functionality ??

_________________
Jakub Miszkurka


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 7:02 pm 
Newbie

Joined: Fri Jun 01, 2007 7:03 pm
Posts: 3
See..
http://www.hibernate.org/hib_docs/v3/re ... irect.html

It appears that the bulk updating is limited to having only one class in the from clause. In your HQL you only have one class but you really need to join on your referenced objects (i.e. the Category and CategoryGroup which are present in the where clause). However, you can have joins in a subquery found in the where condition. You may want to try that avenue. Depending on how you have mapped your tables and classes, you may be able do something like this.

Code:
update Parameter
set value = :desc
where parameterId in (
  select p.parameterId
  from Parameter p
  join ParameterCategory pc
  join ParameterCategoryGroup pcg
  where pcg.name = :groupName
)


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.