-->
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: Left Outer Join with restrictions on both tables
PostPosted: Fri Feb 05, 2010 11:10 am 
Newbie

Joined: Fri Feb 05, 2010 11:00 am
Posts: 3
Hi all, I am doing a LEFT OUTER JOIN, but I am only able to apply Restrictions on the first table. Is there a way ti apply on the second table as well?

Here is my code:

Code:
Criteria criteria = this.crudService
            .initializeCriteria(Applicant.class).setFetchMode("products",
                  FetchMode.JOIN);


This works (applicant has an applicantName property):
Quote:
criteria.add(Restrictions.eq("applicantName", "Markos")


Neither of these works (product has a productName property)
Quote:
criteria.add(Restrictions.eq("productName", "product1")
criteria.add(Restrictions.eq("products.productName", "product1") // products: the name of the property
criteria.add(Restrictions.eq("Product.productName", "product1") // Product: the name of the DB table


And this is the exception I am receiving saying (if I understand correctly) that the productName property does not exist in Applicant:

Quote:
EJB Exception: ; nested exception is: org.hibernate.QueryException: could not resolve property: products.inventedName of: org.myCompany.applicant.entity.Applicant; nested exception is: org.hibernate.QueryException: could not resolve property: products.inventedName of: org.myCompany.applicant.entity.Applicant


I tried to use an alias, but this generated an INNER JOIN, instead of the LEFT OUTER JOIN I want.

How can I apply restrictions on both tables?


Top
 Profile  
 
 Post subject: Re: Left Outer Join with restrictions on both tables
PostPosted: Mon Feb 08, 2010 6:42 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
I think the error is because your Criteria is on the Applicant and Hibernate is trying to look for the "productName" on Applicant.

Which method for Alias have you tried? some thing like below

List cats = session.createCriteria(Cat.class)
.createAlias("kittens", "kit")
.add( Restrictions.like("kit.name", "Iz%") )
.list();

OR

List cats = session.createCriteria(Cat.class)
.createCriteria("cat.kittens","kit",Criteria.LEFT_JOIN)
.add(Restrictions.like...)

-Srilatha.


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.