-1

Can I pass a properties value inside @Query annotation ? My purpose is to pass native query as such to @Query notation. So, whenever a change is made, i need to update the properties file value only.

Say this getQuery method returns a properties file value;

@Repository
@Transactional
public interface HerRepository extends CrudRepository<Order, String> {

String queryVal= SqlQueries.getQuery("herself");

@Query(name = "herNameQuery", value = queryVal, nativeQuery = true)
List<Object[]> findHerName();

When i tried to use, I am getting this error like,

Value of an annotation Query.value must be a constant expression.

Titus
  • 67
  • 1
  • 1
  • 7
  • Possible duplicate of [Get rid of "The value for annotation attribute must be a constant expression" message](https://stackoverflow.com/questions/16509065/get-rid-of-the-value-for-annotation-attribute-must-be-a-constant-expression-me) – Arnaud Jul 25 '18 at 08:47
  • What is the main benefit of editing a property file instead of a constant? – Jens Schauder Jul 26 '18 at 05:35

1 Answers1

0

your string has to be a constant expression. Have you tried :

private static final String QUERY_VAL = SqlQueries.getQuery("herself");

?