Until the last time I checked, there was nothing in the JPA specification about data load, that is, some default to insert values into tables automatically.
Specifically, Hibernate has a setting hibernate.hbm2ddl.import_files
that allows you to specify SQL files that will be executed when the database is created. Note that this will only work if the database creation type is create
or create-drop
, in the hibernate.hbm2ddl.auto
property.
However, I would not recommend using this function for several reasons:
- Content is specific to each database
- Insert structure may look different from your classes
- This only works on bank creation, can not update or add values
For production, a more specialized solution is better. The most basic would be to develop a routine that is executed at system startup and inserts values if they do not exist.
Otherwise there are several more advanced alternatives for versioning databases. Some examples: