[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3389) HQL generates wrong sql when using subquery on the same table

Gail Badner (JIRA) noreply at atlassian.com
Sun Aug 17 22:05:38 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3389?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30915 ] 

Gail Badner commented on HHH-3389:
----------------------------------

Please attach a runnable test case (Java + mapping) that reproduces this issue.

> HQL generates wrong sql when using subquery on the same table
> -------------------------------------------------------------
>
>                 Key: HHH-3389
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3389
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: query-hql
>    Affects Versions: 3.2.6
>            Reporter: Roman Makowski
>
> I've got following insert in my code:
> String queryString = "INSERT INTO Regg (index, code) "
>                 + "SELECT ( SELECT cast(count(*) - 1 as int) "
>                 + "      FROM Code c2 "
>                 + "      WHERE c2.parent.id = c1.parent.id AND c2.id <= c1.id), c1.code "
>                 + "FROM Code c1 "
>                 + "WHERE c1.parent.id = :DIM_ID";
> Query q = session.createQuery(queryString);
> q.setParameter(DIM_ID, dimId, Hibernate.LONG);
> q.executeUpdate();
> Unfortunately HQLQueryPlan returns following SQL query to the database:
> insert into REG_G ( C_SEQ, C_VALUE )
> select (
> select cast(count(*)-1 as int)
> from REG_CODE code1_
> where code1_.C_DIM_ID=REG_CODE.C_DIM_ID and code1_.C_ID<=REG_CODE.C_ID) as col_0_0_,
> code0_.C_CODE as col_1_0_
> from REG_CODE code0_
> where code0_.C_DIM_ID=?
> where REG_CODE.C_DIM_ID and REG_CODE.C_ID are not resolved to code0_.C_DIM_ID and code0_.C_ID 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list