Hibernate5.x 使用SchemaExport生成数据表

来源:互联网 发布:软件安装app 编辑:程序博客网 时间:2024/04/28 20:34

在学习使用Hibernate生成数据表时,发现Hibernate4.x中的configuration已失效,新语法如下
`import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.Test;

public class TestStudents {

@Testpublic void tsetSchemaExport(){    ServiceRegistry serviceRegistry = newStandardServiceRegistryBuilder().configure().build();    MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( serviceRegistry ).buildMetadata();      new SchemaExport(metadata).create(true, true);  }

}`

0 0
原创粉丝点击