-->
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 error in subquery on the same table as outer table
PostPosted: Thu Jul 17, 2008 10:49 am 
Newbie

Joined: Wed Jul 16, 2008 4:46 am
Posts: 5
Location: UK
Hi, I have following query in my code:

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();

When query is executed I've got following trace:

Code:
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=?

Does anybody know why c1 is not dereferenced to code0_ and there is REG_CODE.C_ID and REG_CODE.C_DIM_ID instead of code0_.C_ID and code0_.C_DIM_ID in my internal query? Of course because of this error I've got an exception:

Code:
15:17:16,007 WARN  [JDBCExceptionReporter] SQL Error: 4104, SQLState: S1000
15:17:16,007 ERROR [JDBCExceptionReporter] The multi-part identifier "REG_CODE.C_DIM_ID" could not be bound.
15:17:16,007 WARN  [JDBCExceptionReporter] SQL Error: 4104, SQLState: S1000
15:17:16,007 ERROR [JDBCExceptionReporter] The multi-part identifier "REG_CODE.C_ID" could not be bound.

Is this a bug in hibernate or am I doing something wrong?

Thanks for help,
morhen


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.