我已经创建了一个.sql来准备我的数据库进行测试。
这里是生成错误的.sql的一部分:
DROP TABLE IF EXISTS announcement;
CREATE TABLE announcement (
id int(11) NOT NULL AUTO_INCREMENT,
date datetime DEFAULT NULL,
title varchar(255) DEFAULT NULL,
content mediumtext,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
LOCK TABLES announcement WRITE;
INSERT INTO announcement VALUES (1,'2015-07-29 10:59:16','Test Anno ','some text');
UNLOCK TABLES;
在Mysql Workbench中执行时,这个scipt工作正常。
但是当通过hibernate执行时:
String sqlScript = readFile("dump.sql", Charset.forName("UTF8"));
//System.err.println(sqlScript);
Query q = em.createNativeQuery("BEGIN " + sqlScript + "END;");
q.executeUpdate();
我明白了:
2015-08-06 16:15:55 ERROR SqlExceptionHelper:146 - 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 'DROP TABLE IF EXISTS announcement;
CREATE TABLE announcement (
id int(11) NO' at line 1
我正在使用:
Properties jpaProperties = new Properties();
jpaProperties.put("hibernate.dialect","org.hibernate.dialect.MySQL5Dialect");
jpaProperties.put("hibernate.enable_lazy_load_no_trans", true);
有人可以帮助我吗? 感谢。