How to insert default data into a table using import.sql file in Hibernate, MySQL application

I am developing an application using Spring MVC (version 3.1), Hibernate (version 3.5) and MySQL. In this application, I create a database schema every time the application starts. I want to insert some default data into several tables using the import.sql script file. To do this, I created import.sql script in the root and used the following statements in sleep mode. CFG. xml file.

<property name="hibernate.hbm2ddl.auto">create</property> <property name="hibernate.hbm2ddl.import_files">import.sql</property> <property name="connection.autocommit">true</property> 

But I am not getting success to insert default data into tables.

I beg you, please.

+6
source share
1 answer

Spring should know where to find the file.

If you are using maven, there are several ways to do this.

you can use classpath: /import.sql and put your file in src / test / resources or src / main / resources, depending on whether it is required only for the test or not.

+5
source

All Articles