[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2121) composite-id master-detail doesn't bound correctly variables

German de la Cruz (JIRA) noreply at atlassian.com
Fri Sep 29 14:17:24 EDT 2006


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

German de la Cruz commented on HHH-2121:
----------------------------------------

well,

After make some research I think I've found the problem.

The problem is the method ComponentType.nullSafeSet(PreparedStatement st, Object value, int begin, SessionImplementor session).

When there is a ComponentType parameter (and it isn't the last parameter) it will fail. That's because the method QueryLoader.bindNamedParameters expected each parameter use one and only one binding (you can see it in for ( int i = 0; i < locs.length; i++ )  - line 507). But the ComponentType use as much binding as properties it has. Then, you can see why the bindings are overlaped.

In query 

             from LineItem ol where ol.order=:order and quantity=:quantity

order uses 2 positions (customerId and orderNumber) and quantity uses 1. Then, order uses the 1st and 2nd position, but quantity tries to use the 2nd too, bacause QueryLoader.bindNamedParameters expected that order uses only one binding

But If you run the query inverting the parameters order

             from LineItem ol where quantity=:quantity and ol.order=:order

It works like a charm.

I think QueryLoader must expect that each Type can use n bindings. It will solve the problem


> composite-id master-detail doesn't bound correctly variables
> ------------------------------------------------------------
>
>          Key: HHH-2121
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2121
>      Project: Hibernate3
>         Type: Bug

>   Components: query-hql
>     Versions: 3.2.0.cr4
>  Environment: hibernate-3.2.CR4, oracle 9i
>     Reporter: German de la Cruz
>     Priority: Blocker
>  Attachments: CompositeIdTest.java
>
>
> After issue HHH-2120, we decided to migrate from Hibernate 3.0.5 to 3.2.CR4. But, after have made the migration, we receive another error related to the variables bound. 
> When I run the attached code (You can see it is the same class in tests in distribution file, but with a new method called testQuery2 that can reproduce the bug) Hibernate generate the following query. 
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> 16:18:19,492 DEBUG AST:266 - --- HQL AST ---
>  \-[QUERY] 'query'
>     +-[SELECT_FROM] 'SELECT_FROM'
>     |  \-[FROM] 'from'
>     |     \-[RANGE] 'RANGE'
>     |        +-[DOT] '.'
>     |        |  +-[DOT] '.'
>     |        |  |  +-[DOT] '.'
>     |        |  |  |  +-[DOT] '.'
>     |        |  |  |  |  +-[IDENT] 'org'
>     |        |  |  |  |  \-[IDENT] 'hibernate'
>     |        |  |  |  \-[IDENT] 'test'
>     |        |  |  \-[IDENT] 'cid'
>     |        |  \-[IDENT] 'LineItem'
>     |        \-[ALIAS] 'ol'
>     \-[WHERE] 'where'
>        \-[AND] 'and'
>           +-[EQ] '='
>           |  +-[DOT] '.'
>           |  |  +-[IDENT] 'ol'
>           |  |  \-[IDENT] 'order'
>           |  \-[COLON] ':'
>           |     \-[WEIRD_IDENT] 'order'
>           \-[EQ] '='
>              +-[IDENT] 'quantity'
>              \-[COLON] ':'
>                 \-[IDENT] 'quantity'
> 16:18:19,532 DEBUG AST:232 - --- SQL AST ---
>  \-[SELECT] QueryNode: 'SELECT'  querySpaces (LineItem)
>     +-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
>     |  +-[SELECT_EXPR] SelectExpressionImpl: 'lineitem0_.customerId as customerId2_, lineitem0_.orderNumber as orderNum2_2_, lineitem0_.productId as productId2_' {FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=ol,role=null,tableName=LineItem,tableAlias=lineitem0_,origin=null,colums={,className=org.hibernate.test.cid.LineItem}}}
>     |  \-[SQL_TOKEN] SqlFragment: 'lineitem0_.quantity as quantity2_'
>     +-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[ol], fromElementByTableAlias=[lineitem0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
>     |  \-[FROM_FRAGMENT] FromElement: 'LineItem lineitem0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=ol,role=null,tableName=LineItem,tableAlias=lineitem0_,origin=null,colums={,className=org.hibernate.test.cid.LineItem}}
>     \-[WHERE] SqlNode: 'where'
>        \-[AND] SqlNode: 'and'
>           +-[AND] BinaryLogicOperatorNode: 'AND'
>           |  +-[EQ] BinaryLogicOperatorNode: '='
>           |  |  +-[SQL_TOKEN] SqlFragment: 'lineitem0_.customerId'
>           |  |  \-[SQL_TOKEN] SqlFragment: '?'
>           |  \-[EQ] BinaryLogicOperatorNode: '='
>           |     +-[SQL_TOKEN] SqlFragment: 'lineitem0_.orderNumber'
>           |     \-[SQL_TOKEN] SqlFragment: '?'
>           \-[EQ] BinaryLogicOperatorNode: '='
>              +-[DOT] DotNode: 'lineitem0_.quantity' {propertyName=quantity,dereferenceType=4,propertyPath=quantity,path={synthetic-alias}.quantity,tableAlias=lineitem0_,className=org.hibernate.test.cid.LineItem,classAlias=ol}
>              |  +-[IDENT] IdentNode: '{synthetic-alias}' {originalText={synthetic-alias}}
>              |  \-[IDENT] IdentNode: 'quantity' {originalText=quantity}
>              \-[NAMED_PARAM] ParameterNode: '?' {name=quantity, expectedType=org.hibernate.type.IntegerType at d81b4}
> 16:18:21,968 DEBUG SQL:393 - 
>     select
>         lineitem0_.customerId as customerId2_,
>         lineitem0_.orderNumber as orderNum2_2_,
>         lineitem0_.productId as productId2_,
>         lineitem0_.quantity as quantity2_ 
>     from
>         LineItem lineitem0_ 
>     where
>         lineitem0_.customerId=? 
>         and lineitem0_.orderNumber=? 
>         and lineitem0_.quantity=?
> 16:18:21,988 DEBUG StringType:80 - binding 'C111' to parameter: 1
> 16:18:21,993 DEBUG IntegerType:80 - binding '0' to parameter: 2
> 16:18:21,997 DEBUG IntegerType:80 - binding '2' to parameter: 2
> 16:18:22,019  WARN JDBCExceptionReporter:71 - SQL Error: 1008, SQLState: 72000
> 16:18:22,024 ERROR JDBCExceptionReporter:72 - ORA-01008: not all variables bound
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> As you can see, two variables are binded to parameter 2.

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