0

I have the following in DAO class for my filter condition

ParameterExpression<Long> pexp = criteriaBuilder.parameter(Long.class,"empNo");

criteria.add(criteriaBuilder.equal(emp.get(Employee_.empNo),pexp));

As you can see my empNo is of type Long, how can I use if I would want to use like instead of equal? I tried as

criteria.add(criteriaBuilder.like(emp.<Long>get(Employee_.empNo), pexp)); // gives compilation errors

Edit 1

I have tried the following as well

criteria.add(criteriaBuilder.like(emp.<String>get(Employee_.empNo.toString()),
pexp.toString()));

and this as well

criteria.add(criteriaBuilder.like(emp.<String>get(String.valueOf(Employee_.empNo)),
String.valueOf(pexp)));

However when I run I am getting the following exception

Unable to resolve attribute [org.hibernate.ejb.metamodel.SingularAttributeImpl$Identifier@a21c8
a] against path
java.lang.IllegalArgumentException: Unable to resolve attribute [org.hibernate.ejb.metamodel.Singula
rAttributeImpl$Identifier@a21c8a] against path
    at org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:116)
    at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:221)
    at org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:192)
Jacob
  • 14,463
  • 65
  • 207
  • 320
  • Possible duplicate: http://stackoverflow.com/questions/4269389/using-jpa-2-0-criteria-api-and-cast-causes-generated-jpql-to-fail-in-hibernate – perissf May 10 '13 at 19:28
  • @perissf How to resolve this issue? If it is a bug, which version has the bug being fixed? I am using Hibernate 4.0 – Jacob May 10 '13 at 19:32

0 Answers0