Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Criteria Query Expression isNull() not working
Criteria Query Expression isNull() not working [message #819050] Mon, 12 March 2012 08:33 Go to next message
Eclipse UserFriend
I got like query
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<Afiliacion> query = cb.createQuery(getEntityClass());
        Root<Afiliacion> from = query.from(getEntityClass());
        query.select(from).
                where(cb.and(cb.equal(from.get(Afiliacion_.institucion), institucion),
                cb.equal(from.get(Afiliacion_.cerrada), true)
//                , from.get(Afiliacion_.recibo).isNull()
                ));


if I uncomment the line "from.get(Afiliacion_.recibo).isNull()" the query doesn't works.
This is a very simple query and i dont know what can it be wrong

PD: the column on the DB is <null>
and the mapping in Afiliacion.class is:
    
@ManyToOne
    private Recibo recibo; //UNIDIRECTIONAL



here is the problem.. eclipse is looking on Recibo too
SELECT t1.ID, t1.BAJA, t1.BARCODE, t1.CERRADA, t1.CODIGO, t1.CREATION, t1.OBSERVACION, t1.INSTITUCION_ID, t1.RECIBO_ID, t1.SECTOR_ID, t1.USUARIO_ID FROM RECIBO t0, AFILIACION t1 WHERE ((((t1.INSTITUCION_ID = ?) AND (t1.CERRADA = ?)) AND (t1.RECIBO_ID IS NULL)) AND (t0.ID = t1.RECIBO_ID))

how could I avoid this behavior?

[Updated on: Mon, 12 March 2012 08:43] by Moderator

Re: Criteria Query Expression isNull() not working [message #825189 is a reply to message #819050] Tue, 20 March 2012 11:27 Go to previous message
Eclipse UserFriend
> from.get(Afiliacion_.recibo)

This implies a join. By default is JPA joins are INNER joins, which will filter any null rows. You need to use an outer join, so need to leftJoin the relationship instead of using get.
Previous Topic:Shared cache returning same object (identity) to different sessions?
Next Topic:JPA Queries with Historical Session
Goto Forum:
  


Current Time: Tue Jul 22 21:19:02 EDT 2025

Powered by FUDForum. Page generated in 0.21541 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top