Reputation: 1339
I am newbie to Hibernate criteria and I got problem with simple obtain class. Assume we have classes:
Class A{
int id;
List<A> aList;
}
and:
Class B{
A a;
(...)
}
and :
Class C{
int id;
String name;
B b;
}
I want to get List< C > if 'name' like 'abc'. Here is my criteria code:
Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
Criteria crit = session.createCriteria(C.class);
crit.add(Restrictions.like("nazwa", "%"+string+"%").ignoreCase());
return crit.list();
I got exception:
org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = integer
In my SQL query generated by criteria I can see "left outer join" on my A and B classes that are contained in my C class. Probably that's why I cannot load
Upvotes: 0
Views: 381
Reputation: 27880
There will be left outer joins if the associations are @OneToOne
or @ManyToOne
, just because they are eager in the ToOne owning side by default.
If you want to use such a LIKE
clause, use MatchMode.ANYWHERE
and ilike
instead:
add(Restrictions.ilike("nazwa", string, MatchMode.ANYWHERE))
Also, make sure the property you want to query in class C
is named nazwa
(it is typed as name
in the code example), and it has a proper getter/setter.
Upvotes: 1