hibernate criteria OneToMany, ManyToOne and List
Posted
by jrsokolow
on Stack Overflow
See other posts from Stack Overflow
or by jrsokolow
Published on 2010-01-19T21:27:46Z
Indexed on
2010/03/25
4:03 UTC
Read the original article
Hit count: 521
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.
© Stack Overflow or respective owner