Hibernation criteria are contained in relation to table binding

I have a Hibernate mapping that looks something like this:

<class name="MyEntity">
  <set name="scalarSet" table="(select fk, scalar_value from other_table)">
    <key column="fk"/>
    <property column="scalar_value" type="long"/>
  </set>
</class

      

With this in mind, how can I request that the value of MyEntity.scalarSet (which is set) is in a different collection.

Something like:

criteria.add(Restrictions.in("scalarSet", targetList));

      

[edit] I also tried Restriction.sqlRestriction (..). The SQL query I used looks something like this:

"1 == (select fk, scalar_value from other_table where fk = {alias}.id and scalar_value in ({expanding?})"

      

Where {extension?} 'Is replaced by comma-separated question marks (depending on targetList.size ()).

But I just get

Caused by: org.hibernate.MappingException: Collection was not an association: MyEntity.scalarSet

+2


source to share


2 answers


Your set is a collection, not a mapping of associations - there are subtle but important differences. Using the Hibernate Query API for Collections is currently not supported .

You need to either use HQL or use one-to-many association mapping by creating an object with a Long property, for example:



public class Scalar {
  private Long value;
  public Long getValue() { .... }
  public void setValue(....) { ....}
}

      

+3


source


However, someone wrote a patch that may or may not end in Hibernate 3.4



+2


source







All Articles