Menelaos
Menelaos

Reputation: 25727

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?

Upvotes: 9

Views: 15484

Answers (2)

Lucas Amaral
Lucas Amaral

Reputation: 61

@Query("select p FROM Partner p JOIN p.partnerIdentifier")
    List<Partner> findAfterDates();

You don't need NOT NULL statement you'd just get null values if using LEFT JOIN

Upvotes: -1

Menelaos
Menelaos

Reputation: 25727

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.

Upvotes: 10

Related Questions