Home > Mobile >  Multiple parameter in JPA query and method
Multiple parameter in JPA query and method

Time:01-08

I want to pass multiple parameters around(20) in my JPA method. So is there any way with 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

CodePudding user response:

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

  •  Tags:  
  • Related