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
|