-->
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.  [ 5 posts ] 
Author Message
 Post subject: setParameterList causing error if the collection is empty
PostPosted: Sun Jul 10, 2005 12:00 am 
Beginner
Beginner

Joined: Fri Feb 20, 2004 6:15 pm
Posts: 38
I'm building a query
"from Lease lease where lease.property.propertyId in :properties"

and then using setParameterList("properties", properties);

This works fine if there are properties in the properties object. However, if that collection is empty, then Hibernate causes an error as shown below. I don't think this should be Hibernate's behavior. It seems like it should translate to just () and then notice that the IN clause cannot be satisfied.

Am I doing something wrong or is this just how it works? Is this a bug? Otherwise, I need to add conditional check in my code for whether properties is empty or not.


Hibernate version:
3.0.5

Full stack trace of any exception that occurs:
org.hibernate.hql.ast.QuerySyntaxError: unexpected token: and near line 1, column 91 [from edu.uiuc.cs411.rentalproperty.domain.Lease lease where lease.property.propertyId in]
org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:74)
org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:214)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:414)
org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:814)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:773)
org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
edu.uiuc.cs411.rentalproperty.struts.action.ApplicationEntryAction.execute(ApplicationEntryAction.java:65)


Name and version of the database you are using:
MySQL


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 12:19 am 
Beginner
Beginner

Joined: Fri Feb 20, 2004 6:15 pm
Posts: 38
i meant (:properties), but same error


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 10:12 am 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
Well, consider what the generated SQL would be. Wouldn't

Code:
SELECT * FROM SOME_TABLE WHERE SOME_COLUMN IN ()

be an invalid query? HQL is probably no different in this respect.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 11:47 am 
Beginner
Beginner

Joined: Thu Apr 21, 2005 5:37 am
Posts: 45
Location: Switzerland
I had exactly the same problem today.
well, I think hibernate should just parse this part of the query and resolve it to true or 1=1 or something.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 12:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
or simply use a database that handles this.

_________________
Max
Don't forget to rate


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