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: Problem in query that use a composite-id
PostPosted: Tue May 16, 2006 7:35 pm 
Newbie

Joined: Wed Oct 06, 2004 10:34 am
Posts: 16
Location: Teresina - PI - Brasil
I think Hibernate is generating a wrong SQL related to a composite-id HQL.
The details of the problem are described below...

MAPPING:
Code:
<hibernate-mapping>
    <class name="Cobrador" table="cobrador">
   <composite-id name="id" class="CobradorId">
      <key-property name="empresa"/>
      <key-property name="matricula"/>
   </composite-id>
        <property name="nome" type="string"/>
    </class>
</hibernate-mapping>


HQL:
Code:
from Cobrador cobrador
where cobrador = :cobrador


GENERATED SQL:
Code:
select cobrador0_.empresa as empresa3_,
       cobrador0_.matricula as matricula3_,
       cobrador0_.nome as nome3_,
from cobrador cobrador0_
where (cobrador0_.empresa, cobrador0_.matricula)=?


PARAMETERS BINDING:
Code:
DEBUG 13/05/2006 10:32:18 [org.hibernate.type.IntegerType:80] - binding '1' to parameter: 1
DEBUG 13/05/2006 10:32:18 [org.hibernate.type.IntegerType:80] - binding '1234' to parameter: 2


Note that 2 parameters are binded, but there is just a single parameter in the generated SQL.

DATABASE EXCEPTION:
Code:
org.postgresql.util.PSQLException: The column index is out of range: 2, number of columns: 1


I think the generated SQL should be:
Code:
select cobrador0_.empresa as empresa3_,
       cobrador0_.matricula as matricula3_,
       cobrador0_.nome as nome3_,
from cobrador cobrador0_
where (cobrador0_.empresa, cobrador0_.matricula)=(?, ?)


Is that an Hibernate bug?

_________________
Regis Pires


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 11:47 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I also got the exact error on a composite-id when I tried to have HQL the way you did. There seems something wrong in HQL code that parses especially at IdentNode which as expected is getting both columns.

Someone who developed this code( AST and HqlSqlWalker ) should explain this.


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.