H2 SQL Grammar Exception

前端 未结 2 1111
逝去的感伤
逝去的感伤 2021-01-04 21:02

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

相关标签:
2条回答
  • 2021-01-04 21:45

    I finally found the answer to my question. Based on Ralph's answer, to correct this issue, add the following property for hibernate :

    jpaProperties.setProperty("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
    

    Or in XML :

    <property key="hibernate.hbm2ddl.import_files_sql_extractor" value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" />
    

    This class MultipleLinesSqlCommandExtractor is an implementation of the interface ImportSqlCommandExtractor. This is interface is called when doing SchemaExport with Hibernate. The default implementation is SingleLineSqlCommandExtractor and for unknown reason returns a syntax error. Replacing the single line extractor with the multiple line extractor solved the isssue.

    0 讨论(0)
  • 2021-01-04 21:48

    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

    • @See http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html/ch03.html
    • @See https://hibernate.atlassian.net/browse/HHH-2403
    0 讨论(0)
提交回复
热议问题