Answer the question
In order to leave comments, you need to log in
How to pass a column name to a query?
Hey! I have an interface with @Repository annotation, a method with @Query that executes a native sql query.
This query is bold and consists of many joins. You need to implement 2 methods. The difference is only in one:
where
1) column_1 = id,
2) column_2 = id
I pass the name of the column through the parameter to the Query annotation
@Query(SELECT id FROM table_name WHERE :columnName = 1)
List<Integer> findById(@Param("columnName") String columnName
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question