我的hibernate.cfg.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernateSimpleDB</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="transaction.factory_class">org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
<property name="current_session_context_class">thread</property>
<mapping resource="com/masterhibernate/SimpleHibernateDemo/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
我希望hibernate能够自动创建数据库hibernateSimpleDB
。
但它并没有这样做。
我知道它会自动创建表,但我想自动创建数据库和表。
有可能吗?
答案 0 :(得分:1)
查看http://mojo.codehaus.org/hibernate3-maven-plugin/hbm2ddl-mojo.html
创建表格。
检查此Hibernate属性。
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
这就是制造魔法的路线:
<prop key="hibernate.hbm2ddl.auto">create</prop>