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: Missing expression error when collection is empty
PostPosted: Tue Apr 20, 2004 11:57 am 
Newbie

Joined: Fri Apr 16, 2004 9:27 am
Posts: 18
Location: Russia, Spb
I trying execute HQL expresion by Query using. Collection using as parameter. If collection is empty then Hibernate generate wrong SQL query.
Code:

String select = "select agent from Agent agent where agent.id in :agentIds";

//ids - initialized empty collection of java.lang.Long type

Query query = session.createQuery(select)
    .setParameterList("agentIds", ids, Hibernate.LONG);

return query.list();


In result SQL: SELECT .... WHERE AGENT1_.ID IN

I hoped to see: SELECT .... WHERE AGENT1_.ID IN (NULL)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 2:20 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
do it your self with a test on Collection size... hibernate can do a lot of things but not all...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 7:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You have to put brackets around your named parameter placeholder.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 5:02 am 
Newbie

Joined: Fri Apr 16, 2004 9:27 am
Posts: 18
Location: Russia, Spb
delpouve wrote:
do it your self with a test on Collection size... hibernate can do a lot of things but not all...


:) Yes, but my code have to be easy for understanding.
I think that Hibernate must generate valid SQL for any parameter value (null or empty collection)...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 5:05 am 
Newbie

Joined: Fri Apr 16, 2004 9:27 am
Posts: 18
Location: Russia, Spb
michael wrote:
You have to put brackets around your named parameter placeholder.


I get same SQL code.


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.