方法: public List querySql(String sql) {
//hql风格
//String sql = "select tableClassA.filed1 from tableClassA union select tableClassB.filed1 from tableClassB"
//hql风格
//String sql = "select new map(tableClassA.filed1) from tableClassA union select new map(tableClassB.filed1) from tableClassB"
//原生sql
String sql = "select filed1 from tableA union select filed1 from tableB"
List list = this.getSession().createSQLQuery(sql).list();
return list; }错误提示:
org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before executing the query. [select filed1 from tableA union select filed1 from tableB]
at org.hibernate.impl.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:169)总提示我需要addEntity() or addScalar() 可是我并没有参数什么的啊.我要怎么修改啊?
//hql风格
//String sql = "select tableClassA.filed1 from tableClassA union select tableClassB.filed1 from tableClassB"
//hql风格
//String sql = "select new map(tableClassA.filed1) from tableClassA union select new map(tableClassB.filed1) from tableClassB"
//原生sql
String sql = "select filed1 from tableA union select filed1 from tableB"
List list = this.getSession().createSQLQuery(sql).list();
return list; }错误提示:
org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before executing the query. [select filed1 from tableA union select filed1 from tableB]
at org.hibernate.impl.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:169)总提示我需要addEntity() or addScalar() 可是我并没有参数什么的啊.我要怎么修改啊?
晕
//hql风格
//String sql = "select tableClassA.filed1 from tableClassA "我这样写可以执行出来啊。.....................
但是我这样写就执行不出来了啊。..........................怎么办啊?5555555555555555555555555555 //String sql = "select tableClassA.filed1 from tableClassA union select tableClassA.filed1 from tableClassA "
List list = this.getSession().createSQLQuery(sql).addScalar(field1,Hibernate.STRING).list();
return list;