1

In my spring project, i am using Hibernate to export my entity classes to a previously created database. But I want that, besides the entities/tables, some initial values should be created in the database. Anyone can point a direction of how to do that?

1 Answer 1

4

Place your insert sqls in a file called import.sql in the class path. Once when a SessionFactory is created it would execute this insert script and import all these data.

For example in maven project it would be under \src\main\resources\import.sql

If your import file name is different, you can set it using hibernate.hbm2ddl.import_files property and give your file name.

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

Comments

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.