-->
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: Traversing The Object Graph with Criteria Query
PostPosted: Mon Feb 28, 2005 6:13 pm 
Newbie

Joined: Thu Feb 24, 2005 1:34 pm
Posts: 1
Hi all,

I have been using the criteria API for a few weeks now and it is working great, but I am having one relatively serious problem that I don't see addressed in any documents or examples so far. I can only use the Criteria API to go one association level deep in the object graph. For example I have the following tables. For instance given the following tables...

Code:
-- This is obvious DDL pseudocode, but you get the idea...
create table user(
   user_pk,
   name ,
   create_date,
   user_role_fk
);

create table user_role(
   user_role_pk,
   role_name,
   location_fk
)

create table location
(
  location_pk,
  location_name
)


I can procedurally create queries to return users by the properties user.* and user.user_role.* with the following code:

Code:
Criteria crit = session.createCriteria(User.class); 

crit.createCriteria("user_role", "ur");

crit.createCriteria("ur.location" "loc");


this will create a SQL statement and the appropriate joins. The first 2 createCriteria calls work fine, but the third statement throws an error similar to

Code:
net.sf.hibernate.QueryException: could not resolve property: ur.location of: myPackage.User


The error makes perfect sense to me and I realize I am probably doing something wrong. But for the life of me I can't figure out how to achieve this functionality. Is there any way to do this or is this a limitation of the API?

Thanks,
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 02, 2005 7:42 pm 
Newbie

Joined: Tue Feb 08, 2005 11:59 am
Posts: 2
>>>crit.createCriteria("ur.location" "loc");


I believe your error is the "ur" portion of the "ur.location" string

Seems like you are attempting to reference the location object from the
ur object. Since u already created the criteria to the UserRole object/table, you dont need to reference it in the last createCriteria

I dont normally use the alias parameter so I cant be completely certain that is your problem


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.