9

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?

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

1 Comment

In case You want to use IS NULL remember to use LEFT JOIN.
-1
@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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.