我的sqlStr
中有一个SQL,就像这样:
DELIMITER $$
CREATE TRIGGER TEST_T
AFTER INSERT ON TEST
FOR EACH ROW
BEGIN
INSERT INTO TEST_LOG VALUES(NEW.ID, 3);
END $$
我使用这样的字符串,在运行我的应用程序时创建触发器:
Transaction t = sessionFactory.getCurrentSession().beginTransaction();
SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sqlPart);
query.executeUpdate();
sessionFactory.getCurrentSession().flush();
t.commit();
但我收到一个例外说:
WARN 2013-04-24 16:12:48,238 [main] org.hibernate.util.JDBCExceptionReporter : SQL Error: 1064, SQLState: 42000
ERROR 2013-04-24 16:12:48,239 [main] org.hibernate.util.JDBCExceptionReporter : 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 'DELIMITER $$
CREATE TRIGGER TEST_T
AFTER INSERT ON TEST' at line 1
请注意,当在MySQL中单独执行时,此sqlStr
内容就可以了。但在这里它无法执行。为什么呢?