Beginner |
|
Joined: Fri Dec 10, 2004 11:46 pm Posts: 37
|
Hi I'm reading the Hibernate Persistence book and trying to implement filters on my application. Everything seems right, but I can't seem to get it working. Everything else works file except when trying to set the filter parameter. Any ideas?
Hibernate: 3.1.3
hibernate.cfg.xml:
<hibernate-configuration> <session-factory> ... <mapping resource="com/mycom/DynamicFilters.hbm.xml"/> <mapping resource="com/mycom/MyClass.hbm.xml"/> ... </session-factory> </hibernate-configuration>
DynamicFilters.hbm.xml:
<hibernate-mapping>
<filter-def name="limitByName"> <filter-param name="name" type="String" /> </filter-def>
</hibernate-mapping>
MyClass.hbm.xml:
<hibernate-mapping>
<class name="com.mycom.MyClass" table="`MY_CLASSES`" dynamic-insert="true" dynamic-update="true">
...
<property name="name" column="`NAME`" /> <filter name="limitByName" condition=":name = NAME"/> </class>
</hibernate-mapping>
In the code:
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
Filter filter = HibernateUtil.getSessionFactory().getCurrentSession().enableFilter("limitByName"); filter.setParameter("name", "John");
|
|