-->
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.  [ 5 posts ] 
Author Message
 Post subject: Criteria search problems?
PostPosted: Thu Oct 19, 2006 11:17 am 
Newbie

Joined: Tue Jul 11, 2006 9:47 am
Posts: 19
Hi,

I have a slight or should I say "major" problem.

I have an object A with a couple of properties but it also has an object B inside and Object B also has a couple of properties.

If I want to use the Criteria API I would use the A.class and ad an expression however since they mapped I would like to search for all the Objects A but based on a property in Object B.

If I use the Criteria API and I try the objectB.name for example but it gives me a "no such property" exception which is understandable since the property is in ObjectB but I still want to be able to search this way.
Is this possible ? If so how?

In my mappings I have a many-to-one to ObjectB from ObjectA...

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 11:29 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
I believe you want this:

http://www.hibernate.org/hib_docs/v3/re ... sociations


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 9:01 am 
Newbie

Joined: Tue Jul 11, 2006 9:47 am
Posts: 19
Nope,

Nothing in there has really helped my problem. Is there something special you need to do in the mapping? Its really an issue I cannot seem to sort out


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 9:18 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
So this didn't work?

Code:
List objectAs = session.createCriteria(A.class)
    .createCriteria("B")
        .add( Restrictions.eq("name", "name_i_want_from_b") )
    .list();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 10:30 am 
Newbie

Joined: Tue Jul 11, 2006 9:47 am
Posts: 19
I will try that, thanks.
Seems it should/could work


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