-->
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.  [ 2 posts ] 
Author Message
 Post subject: possible bug in Session.createFilter?
PostPosted: Thu Apr 28, 2005 10:44 am 
Regular
Regular

Joined: Mon Sep 20, 2004 8:42 am
Posts: 58
Location: Boston, US
I am using the method
Code:
Session.createFilter(Object collection, String queryString)
as shown below where my queryString has "or" criterias.

The collection being filtered is obtained by engagement.getLanes() and I can see the "lane0_.engagement_id = ?" where criteria in the generated SQL. The problem is that the user provided query string in not grouped within paranthesis and as a result when "lane0_.engagement_id = ? " is appened by Hibernate to the user query string, the semantics are totally incorrect when the user query has "or" criterias. For intance in my case I would get "lanes" from engagements other than the the one expected.

Let me know if I'm missing something.

Thanks,
Sanjiv

Hibernate version:3.0.1

Code between sessionFactory.openSession() and session.close():
Code:
Collection nullEntryLanes = session.createFilter(engagement.getLanes(),
  "where this.laneId is null " +
  "or this.serviceGroup is null or this.equipmentGroup is null " +
  "or this.demand is null or this.demand <= 0 or this.distance is null").list();


Name and version of the database you are using: Oracle 9i

Code:
The generated SQL (show_sql=true):
Hibernate: select lane0_.lane_id as lane1_, lane0_.name as name9_, lane0_.demand as demand9_, lane0_.distance as distance9_, lane0_.shipper_price as shipper5_9_, lane0_.shipper_price_unit as shipper6_9_, lane0_.stops as stops9_, lane0_.commodity as commodity9_, lane0_.comments as comments9_, lane0_.businessunit_id as busines10_9_, lane0_.servicegroup_id as service11_9_, lane0_.equipmentgroup_id as equipme12_9_, lane0_.engagement_id as engagement13_9_, lane0_.originlocation_id as originl14_9_, lane0_.destinationlocation_id as destina15_9_, lane0_.round_id as round16_9_, lane0_.closed as closed9_ from lane lane0_ where lane0_.engagement_id = ?  and lane0_.name is null or lane0_.servicegroup_id is null or lane0_.equipmentgroup_id is null or lane0_.demand is null or lane0_.demand<=0 or lane0_.distance is null


The query generated should be :

Code:
select lane0_.lane_id as lane1_, lane0_.name as name9_, lane0_.demand as demand9_, lane0_.distance as distance9_, lane0_.shipper_price as shipper5_9_, lane0_.shipper_price_unit as shipper6_9_, lane0_.stops as stops9_, lane0_.commodity as commodity9_, lane0_.comments as comments9_, lane0_.businessunit_id as busines10_9_, lane0_.servicegroup_id as service11_9_, lane0_.equipmentgroup_id as equipme12_9_, lane0_.engagement_id as engagement13_9_, lane0_.originlocation_id as originl14_9_, lane0_.destinationlocation_id as destina15_9_, lane0_.round_id as round16_9_, lane0_.closed as closed9_ from lane lane0_ where lane0_.engagement_id = ?  and (lane0_.name is null or lane0_.servicegroup_id is null or lane0_.equipmentgroup_id is null or lane0_.demand is null or lane0_.demand<=0 or lane0_.distance is null)



Mapping documents:
Code:
<class name="foo.Engagement" table="engagement" lazy="false">
   <id name="id" column="engagement_id" type="long" unsaved-value="null">
      <generator class="sequence">
         <param name="sequence">engagement_sequence</param>
      </generator>
   </id>
   
   <property name="name" column="name" unique="true" />
   <property name="message" column="message"/>
   
   <set name="lanes" inverse="true" table="lane" lazy="true">
      <key column="engagement_id"/>
      <one-to-many class="foo.Lane"/>
   </set>
...
...

</class>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 1:59 pm 
Regular
Regular

Joined: Mon Sep 20, 2004 8:42 am
Posts: 58
Location: Boston, US
This works in Hibernate 3.0.2

Sanjiv


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

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.