Reputation: 6831
I am a Hibernate beginner. I am following "Java Persistence with Hibernate" book and now in chapter 2.
I just found out that in order to test the hello world class, I have to manually create a Messages table in MySQL manually, I found it tedious to type in all the scheme by hand since it is very error-prone.
I wonder if Hibernate has any tool built in that could create a schema for developer automatically? Thanks in advance!
Upvotes: 0
Views: 769
Reputation: 6732
Hibernate can do that. Depending on your setup there are several ways:
This question has been answered before: Hibernate custom schema creation
Upvotes: 1
Reputation: 34677
Just add <property name="hbm2ddl.auto">update</property>
to your hibernate.cfg.xml file and it will do the schema validation for you. If you don't want to override the contents, then do <property name="hbm2ddl.auto">validate</property>
and it will merely validate it.
Upvotes: 2
Reputation: 2349
Specify hibernate.hbm2ddl.auto
in your hibernate configuration. It will create and drop database according to your need.
Find out more about this on -
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/session-configuration.html
Upvotes: 1