-->
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.  [ 1 post ] 
Author Message
 Post subject: multiple container lists problem
PostPosted: Mon Aug 02, 2010 11:31 pm 
Newbie

Joined: Mon Aug 02, 2010 11:14 pm
Posts: 10
Hey Guys,

Just been frustrated, day after day with a question. Supposed we have something like this.

class Cat{
...
List <Mouse> mice;
List <Toys> toy;


...
@OneToMany(cascade=CascadeType.ALL)
public List<Mouse> getMice() {
return mice;
}


@OneToMany(cascade=CascadeType.ALL)
public List<Toy> getToy() {
return toy;
}
}

Now say I wanna do a criteria query in order to get a cat with id 1 (so I get one cat). But instead of getting all the mice and toys, I wanna get only the mice whose size property is "big", and only those toys whose color property is "blue".

Everytime I do something like this, it doesn't work because the second criteria I create becomes a subcriteria. Can anyone help?

Here is the code I've been trying.

Long catId = new Long(1);
session.createCriteria(Cat.class).add(Restrictions("catId", catId)
.createCriteria("mice", Criteria.Left_Join).add(Restriction("size", "big"))
.createCriteria("toy", Criteria.Left_Join).add(Restrictions("color", "blue")).uniqueResult();

Now obviously this won't work because hibernate thinks color is for the mice criteria. So any ideas as to how to accomplish what I am trying to accomplish? Thank you.


Bear


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.