-->
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: Criteria search possible on sub-properties?
PostPosted: Thu Jun 03, 2004 7:19 am 
Newbie

Joined: Thu Jun 03, 2004 7:02 am
Posts: 14
Location: UK
Hi all,

I have three objects A, B and C.

A has a property B and B has a property C and C has a property 'id".

I want to use a Criteria query to perform the equivalent of "select * from A where A.B.C.id = 7"

Is this possible, or even desirable?

Are there better alternatives?

I've spent some time searching the forum but can't find anything similar.

Thanks for any help anyone can give.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 7:24 am 
Newbie

Joined: Thu Jun 03, 2004 7:02 am
Posts: 14
Location: UK
Oops, I should have mentioned that I'm using Hibernate 2.1 and that these are all 1-1 relationships and that I tried to follow the instructions in http://www.hibernate.org/hib_docs/refer ... sociations but I just couldn't get it right.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 7:35 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Code:
List result = session.createCriteria(A.class).createCritiera("b").createCriteria("c").add( Expression.eq("id", new Integer(7)) ).list();


You can "nest" criterions.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 7:44 am 
Newbie

Joined: Thu Jun 03, 2004 7:02 am
Posts: 14
Location: UK
That's brilliant, thanks!

I'd nested B already but it didn't occur to me that I could nest again. Morons of the world - unite!


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.