Note that there are some explanatory texts on larger screens.

plurals
  1. POhibernate criteria filtering on a set of enum values
    primarykey
    data
    text
    <p>Hi I'm using Hibernate 3.2 with a 1.6 JDK and Mysql 5.0 I'm trying to use the criteria api to put together a dynamic filter. However when I add a Restriction on a Set of Enums that is a property of my Criteria object I get a org.hibernate.exception.GenericJDBCException. </p> <p>my code is like this:</p> <pre><code>public class FollowUp { ... public Set&lt;AdminCategory&gt; getAdminCategories() {...} public void setAdminCategories(Set&lt;AdminCategory&gt; _arg) { ... } } </code></pre> <p>My hibernate mapping file has a set of Enum values as specified in the hibernate documentation: <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/collections.html#collections-ofvalues" rel="nofollow noreferrer">http://docs.jboss.org/hibernate/stable/core/reference/en/html/collections.html#collections-ofvalues</a>. The file (FollowUp.hbm.xml ) is like this</p> <pre><code>&lt;hibernate-mapping&gt; &lt;typedef class="dao.util.HibernateAdminCategoryType" name="main-category" /&gt; &lt;class name="FollowUp" table="follow_up"&gt; &lt;!-- other properties here --&gt; &lt;set name="mainCategories" table="follow_up_main_categories" fetch="join" lazy="false"&gt; &lt;key column="fup_id"/&gt; &lt;element column="identifier" type="main-category"/&gt; &lt;/set&gt; &lt;!-- other stuff --&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>the criteria filter code is like this:</p> <pre><code>public void runFilter(FollowUpFilter _filter) { Criteria criteria = this.getSession().createCriteria(FollowUp.class); if (_filter.hasMainCategories()) { criteria.add(Restrictions.in("mainCategories", _filter.getMainCategories())); } criteria.setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY ); criteria.setProjection(Projections.rowCount()); Integer count = (Integer) criteria.uniqueResult(); _filter.setTotalSize(count); } </code></pre> <p>When I run my tests (with sql output) I get the following error: </p> <pre><code>Statement parameter 1 not set. org.hibernate.exception.GenericJDBCException: could not execute query </code></pre> <p>the sql output is as follows:</p> <pre><code>select count(*) as y0_ from follow_up this_ where this_.id in ( ? ) </code></pre> <p>Does anyone know the correct way to filter on a set of enum values in a Criteria (in Hibernate 3.2)?</p> <p>Cheers Simon</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload