-->
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.  [ 4 posts ] 
Author Message
 Post subject: what's wrong with my Criteria..?
PostPosted: Mon Oct 22, 2007 12:06 pm 
Beginner
Beginner

Joined: Mon Oct 01, 2007 6:23 am
Posts: 20
Hii,

Im wondering if this is the right maner to select by criteria..

my classes:

Code:
public class Person{

private User user;
}
public class User {

private Company company;
...

}

public class Company{

private log companyId;
private String name;
...
}


the criteria is simple:
Code:
DetachedCriteria crit = DetachedCriteria.forClass(Person.class)
.createAlias("user", "u")
.add(Restrictions.eq("u.company.name", "myCompany"))
.setFetchMode("user.company", FetchMode.JOIN);


I get a strange exception..

Code:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: company.name


NB: if I change company.name by company.companyId works!!!

thanks for help!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 10:47 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
I think you need to create alias for company too. Try something like

DetachedCriteria crit = DetachedCriteria.forClass(Person.class)
.createAlias("user", "u")
.createAlias("company","c")
.add(Restrictions.eq("c.name", "myCompany"));

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 12:29 pm 
Beginner
Beginner

Joined: Mon Oct 01, 2007 6:23 am
Posts: 20
thanks sethrohit1977..
with alias it works, i dont understand why i dont need alias for other objects..


best regards !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 1:09 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Criteria api doesn't traverse through associations by itself. createAlias actually creates a aliased join for an association. While using criteria queries you need to create aliases for a association to create a join condition and then only you would be able to put restriction on properties of joined objects.

HTH

_________________
Please rate this post if you find it helpful


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