生成表结构
大家的测试类怎么写的,求助
大家的测试类怎么写的,求助
2017-06-04
如果用的是Hibernate5.x, 可以这样写 package entity; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.service.ServiceRegistry; import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.schema.TargetType; import org.junit.Test; import java.util.EnumSet; /** * Created by marhone on 6/4/17. */ public class StusentsTester { @Test public void testSchemaExport(){ ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build(); Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata(); SchemaExport schemaExport = new SchemaExport(); // Hibernate4.x, 可以直接用true参数 schemaExport.create(EnumSet.of(TargetType.DATABASE), metadata); } }
举报