-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate binds index query variable to wrong position
PostPosted: Thu Aug 24, 2006 6:05 pm 
Newbie

Joined: Fri Feb 20, 2004 2:22 pm
Posts: 3
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.