-->
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.  [ 2 posts ] 
Author Message
 Post subject: Criteria error
PostPosted: Thu Dec 06, 2007 12:48 pm 
Newbie

Joined: Tue Dec 04, 2007 10:20 am
Posts: 13
Hi everyone:

I'm trying to implement a method that returns a criteria. The idea is that I get a full criteria (join of three tables) and later I want to compare firstly an attribute of the first class and later an attribute of the third class, so I do.

Code:
return getSession().createCriteria(First.class,"fir").createAlias("second","sec").createAlias("third","thi");


When I debug it, in the variable crit I can see that sec's parent class is First.class and the thi's parent class is also First class, but actually, thi's parent class is Second.class.

After that when I do

Code:
add(Restrictions.eq(fir.name,x.getName()).add(Restrictions.eq(thi.name=y.getName())


I get this error:

Code:
could not resolve property: third of: x.x.x.x.x.first


My question is: Is there any way to use Criteria in order to get that thi's parent class is Second.class??? I suppose that is the reason why I get that error.

Thank you very much in advance[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 07, 2007 4:51 am 
Newbie

Joined: Wed Sep 06, 2006 7:32 am
Posts: 6
You should simple be able to use:
Code:
return getSession().createCriteria(First.class,"fir").createAlias("second","sec").createCriteria(Second.class).createAlias("third","thi");

to do what you want - createAlias() simply returns an instance of the original criteria for method chaining, so you need to explicitly navigate to the child criteria with createCriteria(Second.class)[/code]


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