Going by the Spring Boot reference manual, there are a couple of ways in which we can import data on startup of an application. Combined with an in-memory database, this is rather handy for testing.
The options are to create a file called import.sql
, which will be picked up by Hibernate, or to create a file called data.sql
, which will be picked up by Spring JDBC. Both of these work fine for me.
However, I like to break up my projects a bit, so I currently have a core domain model, where there are some handy imports to configure core data such as some users, which is used everywhere. I also have function-specific projects where it is useful to re-use that same import of base data, but also import some additional data which is specific to that function.
This is where things are not working so well.
I found an answer to a previous question, where Pascal Thivent mentioned that the hibernate.hbm2ddl.import_files
property could be used to define a list of files, as of Hibernate 3.6.0.Beta1. Given that my project is importing 4.3.1.Final, I thought that perhaps this would be available.
So I tried adding the following to my Spring Boot application.properties
:
spring.jpa.hibernate.hbm2ddl.import_files=/another-import.sql
and:
hibernate.hbm2ddl.import_files=/another-import.sql
Unfortunately, neither of these would cause the import to run.
So I'm wondering whether I just made a mess of the properties above (quite likely). Or is there something else that I need to do?
Note that as a workaround, I spotted that Spring JDBC seems to run data.sql
after Hibernate runs import.sql
. So as long as I don't need more than two imports, I'm able to use import.sql
for the base data and then put project-specific imports in data.sql
. I can get by with this, but it's not really a solution.
question from:
https://stackoverflow.com/questions/24508223/multiple-sql-import-files-in-spring-boot 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…