Here the database schema:
Table A: public class A {
id integer, B objectB;
comment varchar(30), String comment;
id_B integer }
Table B: public class B {
id integer, C objectC;
comment varchar(20), String comment;
network integer }
Table C: public class C {
id Integer id;
name varchar(30) String name;
}
Now I need to create a Criteria that checks for the proper 'id' in Table C and the 'comment' in Table B. I tried to do:
Criteria criteria = getSession().createCriteria(A.class);
criteria.createCriteria("objectB")
.createCriteria("objectC").add(Restrictions.idEq(networkID));
//gives org.hibernate.QueryException: duplicate association path: objectB error
if (comment != null && comment.length() > 0) {
criteria.createCriteria("objectB")
.add(Restrictions.like("comment", "%" + comment + "%"));
}
//second approach gives me no error but does not work, means I receive the wrong results
if (comment != null && comment.length > 0) {
criteria.add(Restrictions.like("comment", "%" + comment + "%"));
}