java - Hibernate Criteria, Integer and "like" -
i'm migrating of hql-statements criterias i'm figuring 1 problem: entity property type integer need wildcards search, in hql do
session.createquery("from p1 id :id").setstring("id", "%"+s+"%")
no problem @ all, hibernate casts string integer.
if try in criteria, classcastexception
string cannot cast integer criteria crit = sessionfactory.getcurrentsession().createcriteria(p1.class); crit.add(restrictions.like("id",s)).addorder(order.asc("id")).setmaxresults(maxresults);
why hibernate handle both situations differently?
you use str expression conversion. if makes sense.
str() converting numeric or temporal values readable string
session.createquery("from p1 str(id) :id").setstring("id", "%"+s+"%")
this quite slow if not have function based index on column.
Comments
Post a Comment