6

I have situation in which I have to compose a JPQL query in some method, then pass this query to spring data query method to be used as the query in @Query annotation

@Query(value = ":DyanamicQuery")
List<PrizeInsuranceConfiguration> filterConfigurPrizeInsurance(String DyanamicQuery);

or at least the conditions part

@Query(value = "SELECT c FROM PrizeInsuranceConfiguration c WHERE  :DyanamicConditions")
List<PrizeInsuranceConfiguration> filterConfigurPrizeInsurance(String DyanamicConditions);

1 Answer 1

2

Do, you can do that. There are two reasons why not:

  1. sql injection (spring data work with prepared statements);
  2. (result of first reasone) spring data create query tree and bind all params

But if you need dynamic query you can use Specifications, Query by Example or Querydsl.

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.