Hello, I have the code bellow:
Code:
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Dog> criteriaQuery = criteriaBuilder.createQuery(Dog.class);
Root<Dog> mainRoot = criteriaQuery.from(Dog.class);
criteriaQuery.select(mainRoot);
criteriaQuery.where(criteriaBuilder.le(mainRoot.get("hairSize").as(Long.class), 10L));
TypedQuery<Dog> query = em.createQuery(criteriaQuery);
System.out.println(query.getResultList().size()); // result is 9
System.out.println(em.createQuery("select d from Dog d where d.hairSize <= 10L").getResultList().size()); // result is 8
Why is the result not equal?
Am I doing something wrong?
I CANNOT use the Hibernate Criteria or Canonical MetaModel but I must use the JPA Criteria.
My Libraries are:
antlr-2.7.6.jar
asm-3.0.jar
asm-tree-3.0.jar
cglib-2.2.2.jar
commons-collections-3.1.jar
commons-lang3-3.1.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.1.4.Final.jar
hibernate-entitymanager-4.1.4.Final.jar
hsqldb.jar
jakarta-oro-2.0.8.jar
javassist-3.12.0.GA.jar
javax.persistence_2.0.0.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
log4j-1.2.16.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
Thanks