gpt4 book ai didi

spring - H2 SQL语法异常

转载 作者:行者123 更新时间:2023-12-04 03:38:31 24 4
gpt4 key购买 nike

我正在尝试为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指定它

  • @查看http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html/ch03.html
  • @查看https://hibernate.atlassian.net/browse/HHH-2403
  • 关于spring - H2 SQL语法异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17926093/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com