I'm trying to figure out Spring Hibernate - MySQL relationship. My purpose is, when I start the program, it execute the import.sql file within the classpath. I want to do that without destroy existing tables. I found some documentation about execute sql file on startup.
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html
The official spring doc says;
In addition, a file named import.sql in the root of the classpath will be executed on startup.
But, Spring destroy my tables and than execute import.sql file. Is there a way to execute .sql file without lost existing data?
In the below question, he almost wanted the same thing like me.
How to import initial data to database with Hibernate?
But;
This will also work only if hbm2ddl.auto is set to create or create-drop.
I serached a lot but couldn't find a way. Long stroy short, how can I run .sql statement on startup without destroying database?
data.sqlinstead.<property name="hbm2ddl.auto">create-drop</property>. Be sure to set it at at mostvalidate.application.propertiesspring.datasource.initialize=true spring.datasource.data= classpath: data.sql hibernate.hbm2ddl.auto = and mydata.sqlfile in the src/main/resources folder likeapplication.propertiesfile.data.sqleverything else can remain as is. The file will be executed by default. Also please don't add code as comments improve your question with it.