Kleber Mota
Kleber Mota

Reputation: 9095

How fill tables from database with initial values through Hibernate

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?

Upvotes: 1

Views: 1102

Answers (1)

Jay
Jay

Reputation: 9499

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.

Upvotes: 4

Related Questions