1
同樣的查詢在mysql workbrench工作正常,但是當我在程序中運行它沒有結果,甚至沒有錯誤。真的不知道如何解決這個問題。更新查詢,工作正常,但不是我島類
我使用休眠5.0.0和MySQL連接器5.0.5
道看起來像這樣:
Session session = null;
Transaction tx = null;
try {
session = HibernateAnnotationUtil.getSessionFactory().openSession();
tx = session.beginTransaction();
String hql = "UPDATE cms_asset SET `value` = CASE application_structure_id "
+ "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
+ "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
+ "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
+ "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
+ "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
+ "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
+ "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
+ "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
+ "WHEN (select id from application_structure where `name` = ? and cms_id = ?) THEN ? "
+ "ELSE `value` END WHERE application_structure_id > 0;";
Query query = session.createSQLQuery(hql);
query.setParameter(0, "asd");
...
query.setParameter(26, "asd2");
Integer result = query.executeUpdate();
tx.commit();
if(result > 0){
return true;
}else {
return false;
}
} catch (Exception e) {
try {
tx.rollback();
} catch (RuntimeException rbe) {
rbe.printStackTrace();
}
e.printStackTrace();
return null;
} finally {
if (session != null) {
session.close();
}
}
它完成了嗎?它運行,甚至?它會拋出異常嗎? (只要假設您遺漏的代碼不會削弱該操作)。你調試過了嗎? – Stultuske
它工作正常,但沒有更改數據庫。我沒有堆棧跟蹤。此查詢中的結果是表中的行數。沒有例外,沒有任何東西 – Faron