[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1774) Wrong SQL generated from a composite-id HQL.

Anthony Patricio (JIRA) noreply at atlassian.com
Wed Oct 4 06:07:28 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1774?page=comments#action_24704 ] 

Anthony Patricio commented on HHH-1774:
---------------------------------------

for an HQL query like
from Entity e where e.id = :id
3.2 CR4 works fine.

BUT if you add a restriction like
from Entity e where e.id = :id and e.somethingElse = :anotherParam
it fails, bind parameters indexes are wrong.

i've completed the Hibernate test with this code which fails. 
		s = openSession();
		t = s.beginTransaction();
		Query q = s.createQuery("from Order o where o.id = :id and o.customer.name =:name ");
		q.setParameter("name",o.getCustomer().getName());
		q.setParameter("id",o.getId());
		assertEquals(q.list().size(),1);
		t.commit();
		s.close();


i've attached the class, just update cvs with it package org.hibernate.test.cid.

> Wrong SQL generated from a composite-id HQL.
> --------------------------------------------
>
>          Key: HHH-1774
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1774
>      Project: Hibernate3
>         Type: Bug

>   Components: query-hql
>     Versions: 3.1.3, 3.2.0 cr1, 3.2.0.cr2
>  Environment: Hibernate 3.1.3 / 3.2.0 cr1 / 3.2.9 cr2
> Database: PostgreSQL 8.0 and Oracle 7.3.4
>     Reporter: Regis Pires Magalhaes
>     Priority: Blocker

>
>
> Hibernate is generating a wrong SQL related to a composite-id HQL.
> The details of the problem are described below...
> MAPPING:
> <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:
> from Cobrador cobrador
> where cobrador = :cobrador
> GENERATED SQL:
> select cobrador0_.empresa as empresa3_,
>        cobrador0_.matricula as matricula3_,
>        cobrador0_.nome as nome3_,
> from cobrador cobrador0_
> where (cobrador0_.empresa, cobrador0_.matricula)=?
> PARAMETERS BINDING:
> 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:
> org.postgresql.util.PSQLException: The column index is out of range: 2, number of columns: 1
> The generated SQL should be:
> select cobrador0_.empresa as empresa3_,
>        cobrador0_.matricula as matricula3_,
>        cobrador0_.nome as nome3_,
> from cobrador cobrador0_
> where (cobrador0_.empresa, cobrador0_.matricula)=(?, ?)

-- 
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