Joined: Mon May 23, 2005 4:23 am Posts: 4
|
Hello!
Does Hibernate 3 support filter for many-to-one associations?
I wish to make security subsystem which grant access for partners. Each partner can have products. If user has access to partner it must has access to all his products.
Can the task be solved via filters (I know how to solve this via HQL etc.?).
Hope for any advice.
Hibernate version:3.0.4
Mapping documents:
<class name="package.Product" table="product">
<id name="uuid" type="string" access="field">
<column name="uuid" sql-type="char(32)" not-null="true"/> <generator class="assigned"/></id>
<many-to-one name="partner" access="field" class="package.Partner" outer-join="false">
<column name="partner_uuid" sql-type="char(32)" not-null="true"/>
</many-to-one>
</class>
<class name="package.Partner" table="partner">
<id name="uuid" type="string" access="field" >
<column name="uuid" sql-type="char(32)" not-null="true"/><generator class="assigned"/></id>
<many-to-one name="responsibleEmployee" access="field" class="package.User">
<column name="resp_employee" sql-type="char(32)"/>
</many-to-one>
<filter name="filter" condition="resp_employee =:f"/>
</class>
<filter-def name="filter">
<filter-param name="f" type="string"/>
</filter-def>
Code between sessionFactory.openSession() and session.close():
s.enableFilter("filter").setParameter("f", "XXX");
List persons = s.createCriteria(Partner.class).list();
logger.warn("Number of persons:" + persons.size());
List products = s.createCriteria(Product.class).list();
logger.warn("Number of products:" + products.size());
Name and version of the database you are using:
MSSQL 2000
The generated SQL (show_sql=true):
select ... from partner this_ where this_.resp_employee =?
select ... from product this_ inner join luser user2_ on this_1_.responsible_uuid=user2_.uuid
|
|