-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL - complex update and delete queries
PostPosted: Mon Sep 22, 2008 6:14 am 
Newbie

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

I've got three tables connected as follows:
PARAMETER>------- PARAMETER_CATEGORY >------ CATEGORY_GROUP.

When I try to execute HQL queries of update or delete such as:

1. UPDATE Parameter t SET t.name=? WHERE t.name=? and
t.category.name=? and t.category.categoryGroup.id=? and
t.category.categoryGroup.name=?

2. DELETE FROM Parameter t WHERE t.name=? and t.category.name=?
and t.category.categoryGroup.id=? and
t.category.categoryGroup.name=?

hibernate generates following sql statements (which are incorrect):

1. update PARAMETER, set NAME=? where NAME=? and NAME=? and
CATEGORY_GROUP_ID=? and NAME=?

2. delete from PARAMETER, PARAMETER_CATEGORY parameterc1_,
CATEGORY_GROUP categorygr4_ where NAME=? and NAME=? and
CATEGORY_GROUP_ID=? and NAME=?

I think, that queries should be similar to these:

1. update PARAMETER p
set p.NAME = ?
where p.name = ? and
p.PARAMETER_CATEGORY_ID IN (
select c.PARAMETER_CATEGORY_ID
from PARAMETER_CATEGORY c
c.CATEGORY_GROUP_ID IN (
select CATEGROY_GROUP_ID
from CATEGORY_GROUP
where name = ? and CATEGORY_GROUP_ID = ?))

2. something similiar to 1, with complex subqueires ...


In the other hand, when I executing select query, simalar to this two above, everything is fine. Hibernate joins tables correct:

SELECT t FROM Parameter t WHERE t.name=? and t.category.name=?
and t.category.categoryGroup.id=? and
t.category.categoryGroup.name=?

I don't know if hibernate doesn't have the functionality to create correct sql staments in delete/update queries in complex cases like in this example or if I'm doing something wrong ?

_________________
Jakub Miszkurka


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.