H2 SQL语法异常 [英] H2 SQL Grammar Exception

查看:6255
本文介绍了H2 SQL语法异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为H2导入一个sql脚本。该脚本由spring-batch提供,用于存储作业元数据。当我在H2控制台中直接执行这个脚本时,我没有语法错误,但是在初始化阶段我引用了Hibernate / JPA中相同的脚本来导入,我得到了这个异常:

  org.hibernate.tool.hbm2ddl.ImportScriptException:执行语句时出错(file:'org / springframework / batch / core / schema-h2.sql'):CREATE TABLE BATCH_JOB_INSTANCE(
....
)原因:org.h2.jdbc.JdbcSQLException:SQL语句中的语法错误CREATE TABLE BATCH_JOB_INSTANCE(; expectedidentifier; SQL语句:
CREATE表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]

以下是我正在尝试的脚本前ecute: 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 );

任何想法我可以解决这个问题吗?



import.sql中的语句分隔符是一个换行符。如果你想改变它,那么你需要使用Hibernate> 4.1。您可以实现 MultipleLinesSqlCommandExtractor ,并通过 hibernate.hbm2ddl.import_files_sql_extractor

指定它


I am trying to import a sql script for H2. This script is provided by spring-batch and it's used to store the jobs metadata. When I execute this script directly in the H2 console, I have no syntax errors, but I referenced the same script in Hibernate/JPA to be imported at the initialization phase, I got this exception :

 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]

Here is the script I am trying to execute : https://code.google.com/p/joshlong-examples/source/browse/trunk/batch/src/main/resources/sql/schema-h2.sql?r=2

I am using hbm2ddl to import the sql file :

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");

Any idea how I can solve this issue?

解决方案

Try to write each of your create statements in one line.

The statement delimiter in import.sql is a newline. If you want to change it, then you need to use Hibernate > 4.1. There you can Implement a MultipleLinesSqlCommandExtractor and specify it by hibernate.hbm2ddl.import_files_sql_extractor

这篇关于H2 SQL语法异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆