-->
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: hibernate criteria OneToMany, ManyToOne and List
PostPosted: Wed Jan 20, 2010 4:16 pm 
Newbie

Joined: Wed Jan 20, 2010 4:12 pm
Posts: 1
Hi,

I have three entities ClassA, ClassB and ClassC.

ClassA {
...
@Id
@GeneratedValue
@Column(name = "a_id")
private long id;
...
@OneToMany(cascade={CascadeType.ALL})
@JoinColumn(name="a_id")
private List<ClassB> bbb;
...
}

ClassB {
...
@ManyToOne
private ClassC ccc;
...
}

ClassC {
...
private String name;
...
}
I want to filter by hibernate criteria ClassA by 'name' member of ClassC. So I want to obtain by hibernate criteria list of ClassA objects which have inside ClassC objects with specified name. Problem is that access to ClassC objects is through ClassB list.

I tried something like this but it does not work:

crit.createCriteria("bbb").createCriteria("ccc").add(Restrictions.ilike("name", name, MatchMode.ANYWHERE));

I will be grateful for help.


Top
 Profile  
 
 Post subject: Re: hibernate criteria OneToMany, ManyToOne and List
PostPosted: Mon Oct 03, 2011 2:05 pm 
Newbie

Joined: Tue May 31, 2011 10:12 am
Posts: 4
Hello, jrsokolow. I was facing the same problem and here's the solution I found:
Code:
Criteria parentCriteria = getSession.createCriteria(ClassA.class);
parentCriteria.createCriteria("bbb").createCriteria("ccc").add(Restrictions.like("name", sameVariable));
return parentCriteria.list();

Hope it helps!


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.