I am trying to resolve an issue related to filtering in hibernate, specially when dealing with composite Id's
I have a AttrDesc.hbm.xml
<hibernate-mapping>
<class name="AttrDesc" table="ATTRDESC">
<composite-id>
<key-property name="attr_id" type="long"/>
<key-property name="language_id"/>
</composite-id>
<property name="attrtype_id"/>
<property name="name"/>
<property name="description"/>
<property name="description2"/>
<property name="field1"/>
<property name="groupname"/>
<property name="qtyunit_id"/>
<property name="noteinfo"/>
<filter name="langFilter" condition=":langid=language_id"/>
</class>
<filter-def name="langFilter"> <filter-param name="langid" type="int"/> </filter-def>
</hibernate-mapping>
Issue: I am unable to apply filter on the language_id which is part of composite-id
while debugging I found that the filter-param langid is some how has value as 0 where as actual value that I set using below line of code is -1
session.enableFilter("langFilter").setParameter("langid", -1);
Note: that works if I move language_id out of the composite-id
any help is appreciated, Thanks
For Hibernate jpa 2.1 and above you should modify the mapping a little.
Accordingly, you will need to change the model class to be
And then with
root.get("attrDescId").get("language_id")you will be able to put filter onlanguage_id. Elaborately,