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?

Hossein
  • 107
  • 1
  • 10
  • 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. https://stackoverflow.com/a/15520137/66686 – Jens Schauder Oct 06 '22 at 08:32

1 Answers1

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);
johnnyutts
  • 1,349
  • 1
  • 8
  • 11