-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Filter not applying to native SQL query
PostPosted: Sat Oct 06, 2007 3:13 pm 
Newbie

Joined: Sat Oct 06, 2007 1:57 pm
Posts: 3
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 06, 2007 6:50 pm 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
http://opensource.atlassian.com/project ... se/HHH-626

Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 06, 2007 7:34 pm 
Newbie

Joined: Sat Oct 06, 2007 1:57 pm
Posts: 3
Hi Pavol, thanks for response.

But how is possible at all that filters are not applicable with native sql queries by default? It's pretty common to rely on database features in order to create some query, and in that case using native sql queries is only option. And how hard is to simply implement concatenation with logical AND (filter condition) in WHERE clause in main query, and provide it as a standard feature.

Thanks, again.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 07, 2007 2:33 pm 
Newbie

Joined: Sat Oct 06, 2007 1:57 pm
Posts: 3
Can someone of Hibernate authors please verify that filters are not applicable for native sql queries.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.