0

I have defined the following custom database query.

@Query("select po.* from purchase_order po where po.purchase_order_number = :purchaseOrderNumber")
List<PurchaseOrder> findByPurchaseOrderNumber(String purchaseOrderNumber);

This query always return null regardless of the value of purchas. On the other hand, if I replace the dynamic parameter purchaseOrderNumber in the query with a hard-coded value (as the one depicted below) it perfectly works.

@Query("select po.* from purchase_order po where po.purchase_order_number = "10")
List<PurchaseOrder> findByPurchaseOrderNumber(String purchaseOrderNumber);

I would appreciate it if someone can help me to understand why my query with the dynamic PurchaseOrderNumber doesn't work?

1
  • Please post the actual code you use. The one you posted so far as working doesn't even compile. Also please activate logging of the SQL statement and show the SQL statements that get executed including the bind parameters. stackoverflow.com/a/15520137/66686 Commented Oct 6, 2022 at 8:32

1 Answer 1

0

Specify the name of the query parameter

@Query("select po.* from purchase_order po where po.purchase_order_number = :purchaseOrderNumber")
List<PurchaseOrder> findByPurchaseOrderNumber(@Param("purchaseOrderNumber") String purchaseOrderNumber);
Sign up to request clarification or add additional context in comments.

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.