-->
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: HQL parameter binding with a NULL object
PostPosted: Thu Sep 20, 2007 4:35 am 
Newbie

Joined: Wed Mar 22, 2006 5:43 am
Posts: 15
Location: Belgium
Hibernate version:
3.2.3

I have a problem where a query returns no results.

the hql i used is:
Code:
from Document document where document.owner = ? and document.parent = ?


and i bind that the owner with a User object with id 1 and the parent with a Document that is null.

i cleaned the sql generated by hibernate a bit so its more readable ...

Code:
select
   document0_.id as id5_,
   document0_.name as name5_,
   document0_.created as created5_,
   document0_.updated as updated5_,
   document0_.location as location5_,
   document0_.owner as owner5_,
   document0_.contentType as contentT7_5_,
   document0_.size as size5_,
   document0_.parent as parent5_,
   document0_.directory as directory5_
from
   document document0_
where
   document0_.owner=?
   and
   document0_.parent=?


this gives results in a empty resultset ... (does it fill in '1' and 'null' ??)

while when i run this query directly on the db :

Code:
select
   document0_.id as id5_,
   document0_.name as name5_,
   document0_.created as created5_,
   document0_.updated as updated5_,
   document0_.location as location5_,
   document0_.owner as owner5_,
   document0_.contentType as contentT7_5_,
   document0_.size as size5_,
   document0_.parent as parent5_,
   document0_.directory as directory5_
from
   document document0_
where
   document0_.owner=1
   and
   document0_.parent IS NULL;   


i get the results i want. also when binding with a parent Document that is not null then it works ok.

but some of my documents don't have a parent and have a <null> value in the db, instead of a document id.

of course i cant test whether parent is null and use another method on my DAO but i think it would be nicer if i could just use the same method when the parent document is null or not.

any idea on how to solve this ?

Code:
20 sep 2007 10:13:48 DEBUG org.hibernate.engine.query.QueryPlanCache - located HQL query plan in cache (from Document document where document.owner = ? and document.parent = ?)
20 sep 2007 10:13:48 DEBUG org.hibernate.engine.query.HQLQueryPlan - find: from Document document where document.owner = ? and document.parent = ?
20 sep 2007 10:13:48 DEBUG org.hibernate.engine.QueryParameters - parameters: [com.contentprint.printmanager.customer.User#1, null]
20 sep 2007 10:13:48 DEBUG org.hibernate.engine.QueryParameters - named parameters: {}
20 sep 2007 10:13:48 DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
20 sep 2007 10:13:48 DEBUG org.hibernate.SQL - select document0_.id as id5_, document0_.name as name5_, document0_.created as created5_, document0_.updated as updated5_, document0_.location as location5_, document0_.owner as owner5_, document0_.contentType as contentT7_5_, document0_.size as size5_, document0_.parent as parent5_, document0_.directory as directory5_ from document document0_ where document0_.owner=? and document0_.parent=?
20 sep 2007 10:13:48 DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
20 sep 2007 10:13:48 DEBUG org.hibernate.type.IntegerType - binding '1' to parameter: 1
20 sep 2007 10:13:48 DEBUG org.hibernate.type.SerializableType - binding null to parameter: 2
20 sep 2007 10:13:48 DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)


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.