Hi, I have a problem with dynamic hibernate filter, because it's not applying to native sql query. I'm using Hibernate 3.1.
Mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="domain.Document"
table="document">
<id name="id" column="id" type="integer">
<generator class="sequence">
<param name="sequence">Document_id_SEQ</param>
</generator>
</id>
<many-to-one name="createdBy" column="createdBy" class="domain.User" not-null="true"/>
...
<filter name="limitDocumentsByUser"
condition="(createdBy = :userId)" />
</class>
<filter-def name="limitDocumentsByUser" >
<filter-param name="userId" type="int" />
</filter-def>
</hibernate-mapping>
Code:
Code:
...
private static final String User_Permission = "limitDocumentsByUser";
...
Filter filter = session.enableFilter(User_Permission);
filter.setParameter("userId", user.getId());
...
SQLQuery q = session.createSQLQuery("SELECT {d.*} FROM document d");
q.addEntity("d", Document.class);
return q.list();
If I change type of query to be HQL query, filter is applying, and when it's native it's not. Problem is that I quote only part of filter definition, it's ORACLE specific and cannot be used with HQL query.
What I'm doing wrong.
Thanks in advance.
Regards.