-->
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: How to get alias while setting d fetchmode using criteria?
PostPosted: Mon Feb 26, 2007 3:38 am 
Newbie

Joined: Mon Feb 26, 2007 3:22 am
Posts: 2
How to get alias name while setting the fetchmode using criteria?

I want to use left outer join and want to add a filter criteria/restriction over the joining table (not over the encapsulated..)

table1 having 1 to n relation with table2..

i.e. table1 object has a set(collection) of table2 object

i want to filter on the table2 object..
Something like
Code:
Restrictions.eq(“table2_.fieldname”,value)
.. this wont work.. because table2 is a collection for table1 entity!!! But how to do similarly over collection?

By default
Code:
getAlias()
returns the alias name of the encapsulated entity.. and if I use
Code:
createAlias()
it uses inner join…

Is there any solution/way to do left outer join and get the alias name of the joining table?

Thanks inadvance!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 7:16 pm 
Newbie

Joined: Thu Jan 03, 2008 7:12 pm
Posts: 1
Hi gosoft.hibernate,

I'm also facing the same problem and can't find a solution or workaround.

If someone has found a solution, please post here. Thank you.

By the way, I'm on Hibernate 3.1.3


Top
 Profile  
 
 Post subject: solution
PostPosted: Fri Jan 04, 2008 2:41 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Dhashiike,

You take one problem at a time.
First you use a second createCriteria command on the first Criteria, which gives you both an alias and a JOIN type

Code:
Criteria crit=session.createCriteria(Table1.class)
Criteria crit2=crit.createCriteria("collectionOfT2s", Criteria.LEFT_JOIN);


Then you apply your restriction on crit2, not on crit1

Code:
  crit2.add(Restrictions.eq("fieldName", value));



Finally, ask for crit2.list()

This assumes, of course, that T1 has a property called "collectionOfT2s" and that T2 has a property called "fieldName", and that both classes are properly joined in the mapping file.

_________________
Gonzalo Díaz


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.