在hibernate中,我们可以利用框架的一些配置属性和类来自动创建我们需要的表!
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.Test
public void test() throws Exception{
Configuration configuration = new Configuration().configure("com/User/hibernate.cfg.xml");
SchemaExport schemaExport = new SchemaExport(configuration);
schemaExport.create(true,true);
}
}