2

I want to pass multiple parameters around(20) in my JPA method. So is there any way in which I can pass an Object as a parameter in my JPA method? How can I use @Param annotation which can take values from my object and assign it to my native query attributes?

Muhammad Hewedy
  • 29,102
  • 44
  • 127
  • 219
Fardeen mirza
  • 75
  • 1
  • 6

1 Answers1

1

You can get close by using Spel Expressions.

@Query("select u from User u where u.firstname = :#{#customer.firstname}")
List<User> findUsersByCustomersFirstname(@Param("customer") Customer customer);

You can pass an object(like Customer) to your query methods and then use its reference to set your query params.

Check out the official docs for more details

Abdullah Khan
  • 12,010
  • 6
  • 65
  • 78