tags:

views:

18

answers:

1

Is any way to add implicit restriction to entity in HQL? For example when we query list with hql "from Client" we need select only thouse clients, that have some particular system id. System id itself depends on user session. So we need this query to be actually converted to "from Client where systemId=:systemId" although we didn't specify it in original query

A: 

Hibernate Filter is what you're after...

In order to ensure that you are provided with currently effective records, enable the filter on the session prior to retrieving employee data:

Session session = ...;
session.enableFilter("effectiveDate").setParameter("asOfDate", new Date());
List results = session.createQuery("from Employee as e where e.salary > :targetSalary")
         .setLong("targetSalary", new Long(1000000))
         .list();
Tim
Thanks! I think this is what I was looking for
LazySmokier