Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 950
Menelaos Avatar asked Aug 31 '16 11:08

Menelaos


1 Answers

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.

like image 151
Menelaos Avatar answered Sep 18 '22 12:09

Menelaos