How to import initial data to database with Hibernate?

I found this by doing a search on “Hibernate fixtures” :

Hibernate will create the database
when the entity manager factory is
created (actually when Hibernate’s
SessionFactory is created by the
entity manager factory). If a file
named import.sql exists in the root of
the class path (‘/import.sql’)
Hibernate will execute the SQL
statements read from the file after
the creation of the database schema.
It is important to remember that
before Hibernate creates the schema it
empties it (delete all tables,
constraints, or any other database
object that is going to be created in
the process of building the schema).

Source: http://www.velocityreviews.com/forums/t667849-hibernate-quotfixturesquot-or-database-population.html

Give it a try and let us know if it works!

Leave a Comment