-->
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.  [ 6 posts ] 
Author Message
 Post subject: Criteria: Many-to-many
PostPosted: Mon May 21, 2007 5:37 am 
Newbie

Joined: Mon May 21, 2007 5:30 am
Posts: 5
Hi

I've looked for this in the forum (and google, ..), but I have not found something that solves my problem. Maybe I cannot find the right thing, because I do not know what to look for.

I have following Problem (simplified):

Class A {

Set bs; //set of Bs
..

}

And I am searching for all As with several criterias.
One criteria (the problem) is that a property of B (of the Set of Bs) has a special value. For example the colour of B = 'red' or something like that.

when I try
..
criteria.add(Restrictions.eq("a.bs.colour", colour));
..

I reveive an hibernate exception that bs.clour could not be found.
I have also tried to make it a generic set like Set<B> bs; but this did not change the result..

Can anyone give me a tip?

Thank you very much

Best regards,
mcdot

PS.: many-to-many or one-to-many.. (both cases should be the same.. this example is rather one-to-many.. i am sry for the title)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 9:51 am 
Newbie

Joined: Mon May 21, 2007 5:30 am
Posts: 5
no idea?


Top
 Profile  
 
 Post subject: Criteria: Many-to-many
PostPosted: Mon May 21, 2007 10:03 am 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
try to create an alias for bs and then do the query, something like this

Code:
getSession().createCriteria(A.class,"a").createAlias("a.bs","b")...


hope this helps


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 11:50 am 
Newbie

Joined: Mon May 21, 2007 5:30 am
Posts: 5
thank you very much.. i'll try that.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 12:20 pm 
Newbie

Joined: Mon May 21, 2007 5:30 am
Posts: 5
it did not work :(

(A stands for a longer class name)

DetachedCriteria criteria = DetachedCriteria.forClass(A.class, "a"));

criteria.createAlias("a.bs","B");
criteria.add(Restricions.eq("a.bs.dateTime.time", value);

dateTime is an object that has some properties like time. So hibernate needs to check all the bs to find the correct value.

normal objects work fine. Maybe I can configure it that hibernate knows that the set of bs are from the Class B. Or do I need to join tables (hopefully not, because it would keep it much easier if I would be able to configure it)

maybe I haven't understood your tip correctly.

thanks ;)

best regards,
mcdot


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 5:20 am 
Newbie

Joined: Mon May 21, 2007 5:30 am
Posts: 5
maybe another tip or a tip to use it?

would be very nice, because I do not have so much experience with hibernate (it is my second smaller project with hibernate).

thanks a lot

mcdot


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