Hibernate:根据配置文件自动生成表结构的2种方式
生活随笔
收集整理的這篇文章主要介紹了
Hibernate:根据配置文件自动生成表结构的2种方式
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在hibernate中,我們可以利用框架的一些配置屬性和類來自動創(chuàng)建我們需要的表!
1)在配置文件中加入
<property name="hbm2ddl.auto">true</property>2)使用工具類SchemaExport
package com.User;import org.hibernate.cfg.Configuration; import org.hibernate.tool.hbm2ddl.SchemaExport;public class Test {@org.junit.Testpublic void test() throws Exception{Configuration configuration = new Configuration().configure("com/User/hibernate.cfg.xml");SchemaExport schemaExport = new SchemaExport(configuration);schemaExport.create(true,true);} }?
?
總結(jié)
以上是生活随笔為你收集整理的Hibernate:根据配置文件自动生成表结构的2种方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hibernate一个简单实例的各种坑
- 下一篇: 使用Intellij Idea 创建一个