-->
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.  [ 3 posts ] 
Author Message
 Post subject: problem using setParameter with null
PostPosted: Tue Jul 11, 2006 11:03 pm 
Newbie

Joined: Fri May 27, 2005 3:19 pm
Posts: 18
Hibernate version: 3.0

Name and version of the database you are using: MSSQL 7

For some reason when I use a Query, setting parameter to null, like so:

Query:
("... and menuitem.parentMenu = :parent ..")
.....
.setParameter("parent", null, Hibernate.entity(Menuitem.class));

Generated sql shows:

and menuitem0_.relationid=?

That of course doesnt return proper results. However if I use my Query like:

("... and menuitem.parentMenu is null ..") or even
("... and menuitem.parentMenu = null ..")

Generated sql shows:

and (menuitem0_.relationid is null)

which return correct results.

The mapping file looks like this:



<class name="Menuitem" table="menuitem">
<id name="itemid" column="itemid" type="java.lang.Long">
<generator class="native" />
</id>
<property name="itemname" column="itemname"
type="java.lang.String" not-null="true" />
<property name="orderid" column="orderid"
type="java.lang.Integer" not-null="true" />

<bag name="childMenues" cascade="all-delete-orphan" outer-join="false"
inverse="true" lazy="true" batch-size="10" order-by="orderid">
<key column="relationid" />
<one-to-many class="Menuitem" />
</bag>
<many-to-one name="parentMenu" cascade="none"
outer-join="false">
<column name="relationid" not-null="false" />
</many-to-one>
</class>



Is it supposed to behave like that or I am missing something? Thank you for the help, Oleg.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 11:15 pm 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
Yes, it is (partially at least) supposed to behave like that.

The "?" in the SQL is a placeholder for the named parameter, so that is not a bug or a problem.

Sorry I can't help more with why the query isn't working, but the "?" is not inherantly a problem.

_________________
_________________
dan

If what I say is helpful, please rate the post as such by clicking 'Y'. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 11:21 pm 
Newbie

Joined: Fri May 27, 2005 3:19 pm
Posts: 18
Right :) I understand what "?" is, I am sorry for maybe not being clear but the qestion is why menuitem.parentMenu = null and menuitem.parentMenu = :parent where parent is set with null object return different sql.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.