我正在尝试为H2导入一个SQL脚本。该脚本由spring- batch提供,用于存储作业元数据。当我直接在H2控制台中执行此脚本时,没有语法错误,但是我在初始化阶段引用了Hibernate / JPA中要导入的相同脚本,却遇到了以下异常:
org.hibernate.tool.hbm2ddl.ImportScriptException: Error during statement execution (file: 'org/springframework/batch/core/schema-h2.sql'): CREATE TABLE BATCH_JOB_INSTANCE ( .... Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE TABLE BATCH_JOB_INSTANCE ("; expected "identifier"; SQL statement: CREATE TABLE BATCH_JOB_INSTANCE ( [42001-171] at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) ~[h2-1.3.171.jar:1.3.171] at org.h2.message.DbException.get(DbException.java:169) ~[h2-1.3.171.jar:1.3.171] at org.h2.message.DbException.getSyntaxError(DbException.java:194) ~[h2-1.3.171.jar:1.3.171]
这是我要执行的脚本:https : //code.google.com/p/joshlong- examples/source/browse/trunk/batch/src/main/resources/sql/schema-h2.sql?r= 2
我正在使用hbm2ddl导入sql文件:
jpaProperties.setProperty("hibernate.connection.driver_class", "org.h2.Driver"); jpaProperties.setProperty("hibernate.dialect", H2Dialect.class.getName()); jpaProperties.setProperty("hibernate.hbm2ddl.auto", "create-drop"); jpaProperties.setProperty("hibernate.hbm2ddl.import_files", "org/springframework/batch/core/schema-drop-h2.sql,org/springframework/batch/core/schema-h2.sql");
知道如何解决这个问题吗?
尝试将所有create语句写在一行中。
import.sql中的语句定界符是换行符。如果要更改它,则需要使用Hibernate> 4.1。您可以在其中实施MultipleLinesSqlCommandExtractor并通过指定hibernate.hbm2ddl.import_files_sql_extractor
MultipleLinesSqlCommandExtractor
hibernate.hbm2ddl.import_files_sql_extractor