Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Criteria Query Expression isNull() not working
Criteria Query Expression isNull() not working [message #819050] Mon, 12 March 2012 12:33 Go to next message
FiruzzZ Mising name is currently offline FiruzzZ Mising nameFriend
Messages: 19
Registered: October 2011
Junior Member
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 12:43]

Report message to a moderator

Re: Criteria Query Expression isNull() not working [message #825189 is a reply to message #819050] Tue, 20 March 2012 15:27 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

> 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.


James : Wiki : Book : Blog : Twitter
Previous Topic:Shared cache returning same object (identity) to different sessions?
Next Topic:JPA Queries with Historical Session
Goto Forum:
  


Current Time: Thu Apr 25 08:56:21 GMT 2024

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

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

Back to the top