-->
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: Filtering entities with collection of primitives
PostPosted: Fri May 20, 2011 10:27 am 
Newbie

Joined: Fri May 20, 2011 9:44 am
Posts: 1
Hi guys,

I have a problem using Hibernate. I'll try to explain everything as clear as possible, I hope someone can help me. Thanks!

My entity class have a list of Long's as a property:
public class Entity {
private Long id;
private List<Long> roles;
}

Mapping XML:
<class name="Entity" table="ENTITY">
<id name="id" column="ID" type="long">
<generator class="increment" />
</id>
<list name="roles" table="LABEL_ROLES">
<key column="LABEL"/>
<list-index column="IDX"/>
<element column="ROLE" type="long" not-null="true"/>
</list>
</class>

I have a list of Long's as an argument and I need to select all Entities that has at least one role from my argument list. And I cannot accomplish this using Hibernate API.

Here is what I tried:
List<Long> filter; // contains one or more numbers
Criteria searchCriteria = session.createCriteria(Entity.class).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
searchCriteria.add(Restrictions.in("roles", filter)); // probably this statement is not correct
List<Entity> entitiesList = searchCriteria.list(); // here I got an exception - "java.sql.SQLException: No value specified for parameter 1"

In MySQL's log file I tried to find a statement generated, but I couldn't - it seems that Hibernate throws an exception before the actual execution of statement in DB.

And in general, there's not much documentation on how to handle the case of property being a list of numbers.

Thank you for any help.


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.