-->
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.  [ 3 posts ] 
Author Message
 Post subject: Using Filters with join or outer join
PostPosted: Mon Mar 05, 2007 6:47 pm 
Beginner
Beginner

Joined: Tue Aug 30, 2005 2:33 am
Posts: 22
I have been trying to remove all SQL code from Java and some of the queries which have filtering needed, I am using enableFilter as discussed in Chapter 17 of hibernate documentation.

in DemoResponse.hbm.xml

<filter name="filterCode" condition="ASSESSMENT_CODE = :assessmentCode"></filter>

this gets picked up

in DemoRequest.hbm.xml

<filter name="filterId" condition=":fId = F_ID"/>

when using query like this

session.enableFilter("filterCode").setParameter("assessmentCode", "OK");
//this doesn't add to SQL
session.enableFilter("filterId").setParameter("fId", "1");
session.createQuery("from DemoResponse res join res.demoRequest req").list();



Note: if you plan on using filters with outer joining (either through HQL or load fetching) be careful of the direction of the condition expression. Its safest to set this up for left outer joining; in general, place the parameter first followed by the column name(s) after the operator.


The documentation has the above lines. But what I understand from that is
:fId = F_ID or F_ID = :fId makes a difference. I did try both variations.
To make matter simple, I am doing a natural join, no outer join although ultimately I have to do right outer join.

The chapter on filter is good but it is somewhat more elaborated on simple stuff but only those 2 lines on joins. Would be good if few lines of how to was there for filtering on join.



Any help appreciated.


Hibernate version: 3.2rc2

Mapping documents:

Code between sessionFactory.openSession() and session.close():
session.enableFilter("filterId").setParameter("fid", "TST");
session.enableFilter("filterCode").setParameter("assessmentCode", "R");
//this works
List list = session.createQuery("from DemoResponse res, DemoRequest req where res.id.tId = req.id.tId and res.id.sNumber = req.id.sNumber").list();
//this doesn't
List list = session.createQuery("from DemoResponse res join res.demoRequest req").list();



Full stack trace of any exception that occurs:
none.. when doing join the filters from one side are not getting added to the SQL code by SQLGenerator
Name and version of the database you are using:
Oracle 9
The generated SQL (show_sql=true):


DEMO_RESPONSE demores0_ inner join DEMO_REQUEST demoreq1_ on demores0_.T_ID=demoreq1_.T_ID and demores0_.S_NUMBER=demoreq1_.S_NUMBER where demores0_.ASSESSMENT_CODE = :filterCode.assessmentCode



select demores0_.T_ID as T1_2_0_, demores0_.S_NUMBER as SEQUENCE2_2_0_, from DEMO_RESPONSE demores0_ inner join DEMO_REQUEST demoreq1_ on demores0_.T_ID=demoreq1_.T_ID and demores0_.S_NUMBER=demoreq1_.S_NUMBER where demores0_.ASSESSMENT_CODE = ?
Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 09, 2007 1:31 am 
Beginner
Beginner

Joined: Tue Aug 30, 2005 2:33 am
Posts: 22
does anyone know how to enable filters in joins
for the object on the right side


if there is a select for


A join B

filter from B side are not added

the documentation says you have to be careful with that. But what does it mean by careful. Rather than writing careful, could you not write one line to show what is expected in joins


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 9:31 am 
Beginner
Beginner

Joined: Tue Aug 30, 2005 2:33 am
Posts: 22
any thing to add on this anyone???


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.