[hibernate-issues] [Hibernate-JIRA] Commented: (JPA-27) Problem whith criteria search

Samuel Rettore (JIRA) noreply at atlassian.com
Thu Jan 12 12:39:12 EST 2012


    [ http://opensource.atlassian.com/projects/hibernate/browse/JPA-27?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45116#comment-45116 ] 

Samuel Rettore commented on JPA-27:
-----------------------------------

I tried to use it in another way

            ParameterExpression<Date> dt = builder.parameter(Date.class);


                    setParameter(dt, dataSaldo, TemporalType.DATE).

And it worked! informs me would know because the date can not directly compare.

> Problem whith criteria search
> -----------------------------
>
>                 Key: JPA-27
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/JPA-27
>             Project: Java Persistence API
>          Issue Type: Bug
>    Affects Versions: 1.0.0
>            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

        


More information about the hibernate-issues mailing list