Hibernate自动建表

 hibernate支持自动建表功能,需在hibernate.xml文件中添加以下属性:<property name="hbm2ddl.auto">update</property>  

 

1、update:自动根据模型对象来更新表结构,启动web应用程序时会自动检查数据库,并保证数据库与模型对象关系一致。

2、create:启动web应用程序时,自动删除原来的表,新建所有的表。

3、create-drop:启动hibernate时,自动创建表,程序关闭时,自动把相应的表都删除。

hibernate只会建表,不会建库

 4、<property name="hibernate.hbm2ddl.auto" value="update" />:在web程序运行时自动创建|更新|验证数据库表结构。在开发过程中可设置 <property name="hibernate.hbm2ddl.auto" value="none" />

 

 

 

 

 

猜你喜欢

转载自lovezehui.iteye.com/blog/2094482