我想知道是否可以在Hibernate(3.2)中執行一個以SQLQuery#executeUpdate()
調用的分號分隔的SQL更新查詢。一次執行多個本地查詢
我有一個包含多個更新這樣的字符串:
String statements = "UPDATE Foo SET bar=1*30.00 WHERE baz=1;
UPDATE Foo SET bar=2*45.50 WHERE baz=2;...";
我試圖做
Query query = session.createSQLQuery(statements);
query.executeUpdate();
但不斷收到以下錯誤
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near
'UPDATE Foo SET bar=Y WHERE ' at line 3
如果我執行手動的statements
的內容我得到沒有錯誤,所以我假設多個半決賽OLon-separated查詢在Hibernate或JDBC的某個地方造成麻煩。
單獨爲每一行分割statements
字符串和做createSQLQuery(statement).executeUpdate()
是更好嗎?
示例代碼有點偏離,實際上我計算了一些數值,它們應該沒有引號,對不對? – Janne