From: Viatcheslav (JIRA) <no...@at...> - 2006-05-11 14:38:15
|
Wrong order of binding parameters in Restrictions.in for composite primary keys ------------------------------------------------------------------------------- Key: HHH-1743 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1743 Project: Hibernate3 Type: Bug Components: query-criteria Versions: 3.2.0 cr1 Environment: Windows XP, Oracle 10g Reporter: Viatcheslav Attachments: HibernateTest_restrictions_in_parameter_binding.zip There is a table Person with composite primary key: PERSON primary key fields: FAMILY NUMBER For the Criteria Query like List<PersonId> ids = new Vector<PersonId>(); ids.add(new PersonId("SLAVA1", 10L)); ids.add(new PersonId("SLAVA2", 20L)); ids.add(new PersonId("SLAVA3", 30L)); List<Person> persons = session.createCriteria(Person.class) .add(Restrictions.in("id", ids)) .list(); the query is generated select this_.FAMILY as FAMILY0_0_, this_.NUMBER as NUMBER0_0_ from PERSON this_ where (this_.FAMILY, this_.NUMBER) in ((?, ?), (?, ?), (?, ?)) The query is right, but the parameters are bound in wrong order, here is the excerpt from the log: 16:21:33,221 DEBUG [SQL] select this_.FAMILY as FAMILY0_0_, this_.NUMBER as NUMBER0_0_ from PERSON this_ where (this_.FAMILY, this_.NUMBER) in ((?, ?), (?, ?), (?, ?)) Hibernate: select this_.FAMILY as FAMILY0_0_, this_.NUMBER as NUMBER0_0_ from PERSON this_ where (this_.FAMILY, this_.NUMBER) in ((?, ?), (?, ?), (?, ?)) 16:21:33,221 DEBUG [AbstractBatcher] preparing statement 16:21:33,330 DEBUG [StringType] binding 'SLAVA1' to parameter: 1 16:21:33,330 DEBUG [StringType] binding 'SLAVA2' to parameter: 2 16:21:33,330 DEBUG [StringType] binding 'SLAVA3' to parameter: 3 16:21:33,330 DEBUG [LongType] binding '10' to parameter: 4 16:21:33,330 DEBUG [LongType] binding '20' to parameter: 5 16:21:33,330 DEBUG [LongType] binding '30' to parameter: 6 I've made an example (attached, standalone eclipse project with all libs) which demonstrates the problem, but you need running oracle somewhere to run it. See also bug report HH-708 which is predecessor of this. The problem may lay in org.hibernate.criterion.InExpression::getTypedValues. Instead of for ( int i=0; i<types.length; i++ ) { for ( int j=0; j<values.length; j++ ) { Object subval = values[j]==null ? null : actype.getPropertyValues( values[j], EntityMode.POJO )[i]; list.add( new TypedValue( types[i], subval, EntityMode.POJO ) ); } } should be for ( int j=0; j<values.length; j++ ) { for ( int i=0; i<types.length; i++ ) { Object subval = values[j]==null ? null : actype.getPropertyValues( values[j], EntityMode.POJO )[i]; list.add( new TypedValue( types[i], subval, EntityMode.POJO ) ); } } After change have worked for me. But I am not sure whether the syntax of what's going from Restriction.in is database-specific. -- 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 |