Issue
I was trying to query using hibernate and im getting some alias and some other errors. can anyone help me to write code for below query
select columnA,x.columnB ,* from Table_A
inner join Table_B on x.tableA_ID = y.TableB_id
where x.columnC in (3,6) and x.columnD <> 1 and
y.Column2 >= '2021-02-05 15:47:01.000'
I have tried the below code,
String date="2021-02-05 15:47:01.000"
Query query = session.createSQLQuery("select x.columnA,x.columnB ,* from Table_A x\n" +
"inner join Table_B y on x.tableA_ID = y.TableB_id\n" +
"where x.columnC in (1,2) and x.columnD <> 1 and\n" +
"y.Column2 >= '"+date+"'");
resultList= query.list();
error:
Encountered a duplicated sql alias [columnB] during auto-discovery of a native-sql query; nested exception is o
Solution
The issue is resolved by removing the ",*".
Query query = session.createSQLQuery("select x.columnA,x.columnB from Table_A x\n" +
"inner join Table_B y on x.tableA_ID = y.TableB_id\n" +
"where x.columnC in (1,2) and x.columnD <> 1 and\n" +
"y.Column2 >= '"+date+"'");
Answered By - njan
Answer Checked By - Gilberto Lyons (JavaFixing Admin)