如何使用 hibernate 编写 innerjoin 查询?
how to write innerjoin query using hibernate?
我正在尝试使用休眠进行查询,但我遇到了一些别名和其他一些错误。谁能帮我为下面的查询编写代码
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'
我试过下面的代码,
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();
错误:
Encountered a duplicated sql alias [columnB] during auto-discovery of a native-sql query; nested exception is o
您能否说明您使用的是原生 SQL 还是 HQL?在我看来,您在查询中指定了 table 名称而不是实体 类。
问题已通过删除“,*”得到解决。
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+"'");
我正在尝试使用休眠进行查询,但我遇到了一些别名和其他一些错误。谁能帮我为下面的查询编写代码
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'
我试过下面的代码,
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();
错误:
Encountered a duplicated sql alias [columnB] during auto-discovery of a native-sql query; nested exception is o
您能否说明您使用的是原生 SQL 还是 HQL?在我看来,您在查询中指定了 table 名称而不是实体 类。
问题已通过删除“,*”得到解决。
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+"'");