[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2254?page=c...
]
Steve Ebersole commented on HHH-2254:
-------------------------------------
Oh, you forgot another condition on your list ;)
This only happens when using positional parameters. Actually most of the other conditions
on your list are inconsequential. Currently, positional parameters cannot be used for
multi-column values. You must use named parameters.
A query validation bug produces QueryException: "Expected
positional parameter count: 1, actual parameters: [Parent@bec357b] [from Child this where
this.id.parent = ?]"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2254
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2254
Project: Hibernate3
Type: Bug
Components: query-hql
Versions: 3.2.0.ga
Environment: Hibernate 3.2 using Sybase. However this is not an environment caused
problem. It's supposed to happen in every environment.
Reporter: Hernan Liendo
Original Estimate: 1 day
Remaining: 1 day
-- Short description
============================================================================ --
A query validation bug produces QueryException: "Expected positional parameter
count: 1, actual parameters: [Parent@bec357b] [from Child this where this.id.parent = ?].
Both Parent and Child use composite keys.
-- Context
====================================================================================== --
Having composite keys for a Parent class and a Child class, I want to retrieve childs
that belong to an specific Parent.
-- Parent Definition
============================================================================ --
public class Parent {
public ParentId ParentId;
...
}
public class ParentId {
private String idField1;
private int idField2;
...
}
// the parent mapping
<hibernate-mapping>
<class mutable="false" table="xx" name="Parent">
<composite-id class="ParentId" access="field"
name="parentId">
<key-property column="idField1" access="field"
name="idField1"/>
<key-property column="idField2" access="field"
name="idField2"/>
</composite-id>
</class>
</hibernate-mapping>
-- Child Definition
============================================================================ --
public class Child {
public ChildId childId;
...
}
public class ChildId {
public Parent parent;
public String aditionalIdField;
...
}
// the mapping
<hibernate-mapping>
<class mutable="false" table="yyy" name="Child">
<composite-id class="ChildId" access="field"
name="childId">
<key-many-to-one name="parent" class="Parent"
access="field">
<column name="idField1" not-null="true" />
<column name="idField2" not-null="true" />
</key-many-to-one>
<key-property column="aditionalIdField" access="field"
name="aditionalIdField"/>
</composite-id>
</class>
</hibernate-mapping>
-- HQL Statement
============================================================================ --
from Child this where this.childId.parent = ?
or
from Child this where this.id.parent = ? // using aliased id
-- The Exception
============================================================================ --
org.hibernate.QueryException: Expected positional parameter count: 1, actual parameters:
[Parent@bec357b] [from Child this where this.childId.parent = ?]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:319)
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:275)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:75)
...
-- The Problem
============================================================================ --
class: org.hibernate.impl.AbstractQueryImpl
method: protected void verifyParameters(boolean reserveFirstParameter) throws
HibernateException
line: 286
The method validates parameters. It resolves the "positionalValueSpan" variable
witch in my case gets the value of 2 (One for parent's idField1 and the other for
parent's idField2).
The method compares positionalValueSpan (2) with
parameterMetadata.getOrdinalParameterCount() witch it is 1 (the quantity of "?"
signs in the HQL statement".
This bug only happens when:
1. composed keys are used (and)
2. having a parent-child relationship (and)
3. resolving children from certain parent.
-- Hibernate user workaround
============================================================================ --
Not to use a parent instance variable in the Child class.
Hope this helps. If you guys need the source code in order to check the bug, please let
me know it. Good luck!
Hernan
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira