javaspringhibernatejpql

JPQL IS NOT NULL is returning objects with NULL


I have the following JPQL query:

@Query("select p FROM Partner p where p.partnerIdentifier IS NOT NULL")
    List<Partner> findAfterDates();

This should return all Partner Entities that DO NOT have NULL for partnerIdentifier.

However, I am running the code and debugging, and I am seeing that the returned Collection contains entities that has null for this field.

Is this a bug in JPQL?


Solution

  • A colleague came by and suggested I use a join since the inner object was a one to one mapped object.

    The following now returns correct results:

    @Query("select p FROM Partner p join p.partnerIdentifier pi where pi is not null")
    List<Partner> findAfterDates();
    

    Once again a reminder that underneath hibernate we have a relational database and that something that logically should work using oop/jpql doesn't.