-->
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.  [ 10 posts ] 
Author Message
 Post subject: IN + empty collection throws exception
PostPosted: Tue Dec 27, 2005 7:39 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
The following HQL expression fails with a "Not all named parameters have been set" exception.

The query is like this

Code:
from UploadCustodias upload where upload.mFechaDatos = :fecha and upload.mCustodia in (:custodias)



and later:

Quote:
Return this.CreateQuery(hql).SetDateTime("fecha", fecha).SetParameterList("custodias", custodias).List()


When custodias == null I get the exception.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 5:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
what's the point of doing a query and going to the DB if the list is null or empty.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 9:55 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
A null list won't work. An empty list should, but you should then better specify the IType explicitly (use 3-parameter version of SetParameterList).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 11:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Some DBs do not support
Code:
in ( )
in SQL, though

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 11:52 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I added a workaround for this to NHibernate some time ago.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 1:52 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
We set up collections (all properties actually) with field access rather than property access. This allows the property getters to lazy initialize collections to empty ArrayLists, and null strings to empty strings, so that there are no nasty surprises when writing application-level code. Your code shouldn't ever end up with or have to deal with a null collection reference.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 4:59 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
Nels_P_Olsen wrote:
We set up collections (all properties actually) with field access rather than property access. This allows the property getters to lazy initialize collections to empty ArrayLists, and null strings to empty strings, so that there are no nasty surprises when writing application-level code. Your code shouldn't ever end up with or have to deal with a null collection reference.


So you write something like this?
get { if(_field==null) _field = new Arraylist(); return _field; }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 4:51 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
I've managed to solved the problem with 2 queries but was wondering what was the workaround Sergey was referring to.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 12:51 am 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
TheShark wrote:

Quote:
So you write something like this?
get { if(_field==null) _field = new Arraylist(); return _field; }


Exactly.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 6:59 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
roniburd wrote:
I've managed to solved the problem with 2 queries but was wondering what was the workaround Sergey was referring to.


Hibernate 2.1 generates SQL like "in ()" for an InExpression with an empty list. Almost no databases support empty list after in, so NHibernate will instead generate "1=0" in this case.


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