1

I have a spring boot application configured with an application.yml file. I'm also using an import.sql file to load test data into my application using insert statements.

I want the import.sql to support multiline statements.

I found this similar question with an answer using and application.properties file Spring Mvc Hibernate Encoding/Multi-line import sql

However I can't seem to apply that answer to using my application.yml file which I have tried unsuccessfully to do as below

spring:
  jpa:
show-sql: true
  hibernate:
    hbm2ddl:
 import_files_sql_extractor:org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor

For reference I found the documentation for this property here https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/tool/hbm2ddl/ImportSqlCommandExtractor.html

But I still can't seem to configure it properly. Can anyone help? Thanks

Stewart Evans
  • 1,416
  • 1
  • 12
  • 17

2 Answers2

1

I got multi-line import.sql statements working for Spring Boot 2 by adding property prefix "spring.jpa.properties".

So for application.yml configuration it is:

spring:
  jpa:
    properties:
      hibernate:
        hbm2ddl:
          import_files_sql_extractor: org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor
reggoodwin
  • 1,514
  • 13
  • 14
0

in application.yml you can add config:

spring:
    datasource: classpath:/init.sql

or add @SQL(value = "data.sql") annotation in your test class where data.sql has multiple lines sql commands.

  • thanks for your answer. I would really like to get multi line SQL statements working with the default import.sql surely this is possible? – Stewart Evans Oct 12 '17 at 10:29
  • Yes, you can. Try please this configuration - http://plog.roycat.net/?p=557 . In my project I use similar method like this. – Spirited Oct 12 '17 at 14:23