Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] CriteriaBuilder and() isNotNull() equals() problem (BUG 316144)

Hello

Recently I've started using the JPA 2.0 Criteria API. In my first approach I'm already having problems because the API doesn't behave as expected.

My code looks as follows:

        final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        final CriteriaQuery cQuery = cb.createQuery(Long.class);
        final Root root = cQuery.from(ExpedicionD3.class);
        final Path codigoHojaRuta = root.get(ExpedicionD3_.codigoHojaRuta);
        cQuery.select(cb.max(codigoHojaRuta));
        cQuery.where(cb.and(
                //BUG IN ECLIPSELINK https://bugs.eclipse.org/bugs/show_bug.cgi?id=316144
                cb.isNotNull(root.get(ExpedicionD3_.diccionario)),
                cb.equal(root.get(ExpedicionD3_.corresponsalOrigen), origen),
                cb.equal(root.get(ExpedicionD3_.corresponsalDestino), destino)));
        final TypedQuery typedQuery = entityManager.createQuery(cQuery);
        return typedQuery.getSingleResult();

The above TypedQuery resolves to the following SQL:

SELECT MAX(codigohojaruta) FROM expediciond3 WHERE ((corresponsalorigen = ?) AND (corresponsaldestino = ?))
So the isNotNull clause is not taken into account.

When searching for what was happening I came across the following BUG 316144, luckily the bug appears to be fixed.

The problem is that when I downloaded eclipselink 2.2.0 RC3 yesterday to test if I could run my code without problems, the TypedQuery still resolved to an SQL query where the isnotnull clause was omitted.

Is there something wrong in my code or is the BUG still open?

Regards

-- Marc Nuri

View this message in context: CriteriaBuilder and() isNotNull() equals() problem (BUG 316144)
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

Back to the top