6

I am developing an application using Spring MVC (version 3.1), Hibernate (Version 3.5) and MySQL. In this application, I am creating a database schema each time when the application runs. I want to insert some default data into a few tables using import.sql script file. For this I have created import.sql script in the root and using the following statements in hibernate. 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.

Please guide me.

1 Answer 1

5

Spring must know where to find your file.

If you are using maven, there are several way of doing so.

you can use classpath:/import.sql and put your file in src/test/resources or src/main/resources, depending if you need this for test only or not.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Samuel. Actually I was not placing import.sql file in src/main/resources. Now it is working fine for me.
Thank you! After 2h searching, this really helped me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.