I want to apply parameter binding to the dynamic native query where the column name which i am fetching i will be passing that dynamically from the UI.(say emp_id in this case).
Following is the sample java code snippet,
org.hibernate.Query queryMain;
String fetchColumn="emp_id";
String query;
query="select e.:id from Employee e";
queryMain = (org.hibernate.Query) em.createNativeQuery(query).unwrap(org.hibernate.Query.class);
queryMain.setParameter("id", fetchColumn);
But when i execute this code i am getting sql syntax error exception. When i print the sql query i am getting as follows
select 'emp_id' from Employee
Since the column was set in string literals it is throwing the sql syntax exception. Can someone help me on this please. Thanks in advance!