J
J
Jsman2020-01-24 14:16:39
Java
Jsman, 2020-01-24 14:16:39

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

But spring says that you can't do that.
Tell us how you solved this problem?
Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question