0

I have such entity:

public class LogEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer id;
    private Date changeTime;
    private Set<Integer> changes; 

    //getters and setters

}

And its mapping:

<hibernate-mapping>
<class name="com.myproject.dao.LogEntity" table="LOG">
    <id name="id" column="ID" type="integer">
        <generator class="native" />
    </id>
    <property name="changeTime" column="CHANGE_TIME" type="timestamp"/>
    <set name="changes" table="LOG_CHANGES" lazy="false" cascade="all" order-by="CHANGE_ID">
        <key column="ID"/>
        <element column="CHANGE_ID" type="integer"/>
    </set>
</class>

The problem is how to check that Set<Integer> changes contains given parameter using hibernate criteria. I can't createAlias() for this and also try to use sqlRestriction() but get something ugly.

I am pretty sure that there is some easy way but I just cant see it. Thanks for any help.

Ilya
  • 1
  • 2
  • 1
    can you show what you have tried and the issue you are facing in that? – Chaitanya Sep 30 '14 at 16:51
  • I try to do it like this: `criteria.createAlias("changes", "c").add(Restrictions.eq("c.CHANGE_ID", param));` and get org.hibernate.QueryException: illegal syntax near collection: CHANGE_ID. Than I try to use sqlRestriction: criteria.add(Restrictions.sqlRestriction("select * from LOG_CHANGES c where c.CHANGE_ID like ?", param, IntegerType.INSTANCE)); – Ilya Oct 01 '14 at 09:08
  • whatever you are doing is completely wrong, better you go through hibernate documentation to understand how to write Criteria queries. – Chaitanya Oct 01 '14 at 09:15

0 Answers0