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?