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.
|