[
https://hibernate.onjira.com/browse/HHH-7024?page=com.atlassian.jira.plug...
]
Steve Ebersole edited comment on HHH-7024 at 2/6/12 7:13 AM:
-------------------------------------------------------------
The initial criteria and jpql queries you listed are *not* equivalent. The criteria form
is using a literal for the date, while the jpql query is using a parameter for the date.
was (Author: steve):
The initial criteria and jpql queries you listed are *not* equivalent. The criteria
form is using a literal for the date, while the jpql query is using a parameter for the
query.
Use of date literals with JPA criteria queries is broken
--------------------------------------------------------
Key: HHH-7024
URL:
https://hibernate.onjira.com/browse/HHH-7024
Project: Hibernate ORM
Issue Type: Bug
Components: entity-manager
Affects Versions: 4.0.1
Reporter: Samuel Rettore
Two criteria to a search and no one uses criteria that works with JPQL criteria does not
work seems to be the date field where the comparison does not work.
Criteria- fail
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<SrhaplicacaoSaldo> criteriaQuery =
builder.createQuery(SrhaplicacaoSaldo.class);
Root<SrhaplicacaoSaldo> root =
criteriaQuery.from(SrhaplicacaoSaldo.class);
criteriaQuery.select(root);
criteriaQuery.where(builder.equal(root.get(SrhaplicacaoSaldo_.idaplicacao).
get(Srhaplicacao_.idaplicacao), idaplicacao),
builder.equal(root.get(SrhaplicacaoSaldo_.dataSaldo), dataSaldo));
criteriaQuery.orderBy(builder.desc(root.get(SrhaplicacaoSaldo_.dataSaldo)),
builder.desc(root.get(SrhaplicacaoSaldo_.idaplicacaosaldo)));
return em.createQuery(criteriaQuery).
setMaxResults(1).
getSingleResult();
JPQ - OK
return (SrhaplicacaoSaldo) em.createQuery("Select a from SrhaplicacaoSaldo a
where "
+ "a.idaplicacao.idaplicacao=:idaplicacao and a.dataSaldo=:dtsaldo
order by a.dataSaldo,a.idaplicacaosaldo ").
setParameter("idaplicacao", idaplicacao).
setParameter("dtsaldo", dataSaldo).
setMaxResults(1).
getSingleResult();
Tanks.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira