我得到了这个例外:
org.hibernate.QueryException: Not all named parameters have been set: [dua_num] [SELECT rev FROM DUA_AUD WHERE dua_num = :dua_num SELECT rev FROM DUA_DATA_FIL_AUD WHERE dua_num = :dua_num1]
at org.hibernate.internal.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:401)
at org.hibernate.internal.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:195)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:134)
at com.envers.EnversTest.getAllRevisions(EnversTest.java:249)
at com.envers.EnversTest.main(EnversTest.java:56)
Java方法
public void getAllRevisions(){
Session session = factory.openSession();
Transaction tx = null;
try {
String sql = "SELECT rev FROM DUA_AUD WHERE dua_num = :dua_num"
+ "SELECT rev FROM DUA_DATA_FIL_AUD WHERE dua_num = :dua_num1"
+ "union all"
+ "SELECT rev FROM DUA_STUS_AUD where DWHERE dua_num = :dua_num2"
+ "union all"
+ "SELECT rev FROM DATA_PYMT_AUD where WHERE dua_num = :dua_num3"
+ "union all"
+ "SELECT rev FROM DUA_SPLMT_DOC_AUD where WHERE dua_num = :dua_num4"
+ "union all"
+ "SELECT rev FROM ORG_PRTNRSHP_AUD where WHERE dua_num = :dua_num5";
SQLQuery query = session.createSQLQuery(sql);
query.setParameter("dua_num1", 1);
query.setParameter("dua_num2", 1);
query.setParameter("dua_num3", 1);
query.setParameter("dua_num4", 1);
query.setParameter("dua_num5", 1);
List<Number> results = query.list();
for (Number number : results) {
System.out.println("Results: " + number);
}
} catch (HibernateException e) {
e.printStackTrace();
}
}
答案 0 :(得分:1)
我在你的sql查询中看到两个错误: (1)你在第一行和第二行之间省略了'union all' (2)第一行中的第一个参数'dua_num'未设置