-->
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 Or, ilike on Joined Columns
PostPosted: Fri Sep 10, 2010 10:05 am 
Newbie

Joined: Fri Sep 10, 2010 9:57 am
Posts: 1
I'm trying to use Criteria to implement adhoc queries on tables that have multi-tiered relationships.

Code:

Criteria c = session.createCriteria( CaseReview.class );
c.createAlias( "reviewCase" , "reviewCase");
c.createAlias( "reviewCase.studentInformation" , "reviewCasestudentInformation");
c.add( Restrictions.or( Restrictions.ilike("reviewCasestudentInformation.lastName" , "%e%" ), Restrictions.ilike( "reviewCasestudentInformation.firstName" , "%e" )));
c.list();


Where my studentinformation entity has a firstName and lastName attributes, my CaseReview has a reviewCase entity, and my reviewCase entity has a studentInformation attribute.

I end up getting a
Code:
org.hibernate.QueryException: could not resolve property: reviewCasestudentInformation of: CaseReview


which doesn't make any sense to me. The exactly same alias works fine when using the Order api
Code:
// This code works absolutely fine after creating the aliases above
sortOrder = Order.asc("reviewCasestudentInformation.lastName");
criteria.addOrder(sortOrder);
c.list();


I'm about ready to give up. Any suggestions?


Top
 Profile  
 
 Post subject: Re: Criteria Or, ilike on Joined Columns
PostPosted: Sat Sep 11, 2010 4:01 pm 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
You might want to try this:
Code:
Criteria c = session.createCriteria( CaseReview.class );
c.createAlias( "studentInformation" , "si");
c.add( Restrictions.or( Restrictions.ilike("si.lastName" , "%e%" ), Restrictions.ilike( "si.firstName" , "%e" )));
c.list();


Read http://docs.jboss.org/hibernate/stable/ ... sociations

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


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.