hibernate insert data on schema update
I would like to insert some test data while I start my application after schema update. Can this be done automaticly with some hibernate tools? Or do I 开发者_Python百科have to always run insert script each time manually?
Edit: You are right @partenon
Ill sum it up from your link if somebody else will look for the same answer ;)
So this feature can be don trough property
<property name="hibernate.hbm2ddl.auto" value="create" />
create
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).
Sorry, but I have to disagree with Daniel. If you have a "import.sql" file in your classpath, it will be executed against your database.
See http://in.relation.to/9081.lace for more details.
精彩评论