I'm querying values in a map by both map key and value using bound parameters. Hibernate binds the index of the key parameter to the wrong position when generating and binding to a SQL statement. This happens with either positional or named bindings.
Hibernate version: 3.1.3
Mapping documents:
Code:
<class name="com.orbitz.corp.poller.Task" table="corp_task" mutable="true" lazy="false">
<id name="id" column="corp_task_id" access="field">
<generator class="sequence">
<param name="sequence">task_seq</param>
</generator>
</id>
<discriminator column="task_type" type="string" force="true"/>
<map name="attributes" table="corp_task_attribute"
lazy="false" access="field">
<key column="corp_task_id" />
<map-key column="name" type="string" />
<element column="value" type="string" />
</map>
</class>
Code between sessionFactory.openSession() and session.close():Code:
// class discriminator cannot be used as a bind variable
String CLASS_AND_ATTRIBUTE_HQL = "from " + Task.class.getName() + " t"
+ " where t.class = " + c.getName()
+ " and t.attributes[:name] = :value";
Query q = getCurrentSession().createQuery(CLASS_AND_ATTRIBUTE_HQL);
q.setParameter("name", "foo");
q.setParameter("value", "bar");
Name and version of the database you are using:Oracle 9i
Debug level Hibernate log excerpt:Code:
[junit] 9050 [main] DEBUG org.hibernate.SQL - select task0_.corp_task_id as corp1_60_, task0_.created_on as created3_60_, task0_.scheduled_for as scheduled4_60_, task0_.last_worked_on as last5_60_, task0_.priority as priority60_, task0_.task_type as task2_60_ from corp_task task0_, corp_task_attribute attributes1_ where task0_.task_type in ('TEST', 'TEST2') and ((task0_.task_type='TEST' )and(attributes1_.value=? and task0_.corp_task_id=attributes1_.corp_task_id and attributes1_.name = ?))
[junit] 9050 [main] DEBUG org.hibernate.type.StringType - binding 'bar' to parameter: 2
[junit] 9051 [main] DEBUG org.hibernate.type.StringType - binding 'foo' to parameter: 1
As you can see, the "name" and "value" parameters are being bound to the wrong positions.