Skip to content
Advertisement

JPA repository Boolean Query – return null pointer exception

I have Java springBoot project With repository that included boolean custom query. but the system run to null pointer exception apart from return “false”. this is the query:

JavaScript

I called the method:

JavaScript

and this is the error:

JavaScript

Advertisement

Answer

Your query

JavaScript

is designed to return whatever entity (called CustomersVsCoupons from now on) is mapped to the table customer_vs_coupons, not a Boolean.

If you want to throw an exception whenever a specific customer already has a coupon affected, you should transform the signature of your method to either:

  • Return a CustomersVsCoupons, and throw an exception if your query did not return null
  • Return an Optional<CustomersVsCoupons>, and throw an exception if your query did return a non empty Optional
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement