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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -