Java EE之 Hibernate 5.x版本中SchemaExport的用法

时间:2021-08-15 06:50:08
//hibernate 5.0.1 Final
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build(); MetadataImplementor metadataImplementor = (MetadataImplementor)
new MetadataSources(serviceRegistry).buildMetadata(); SchemaExport export = new SchemaExport(serviceRegistry, metadataImplementor);
export.create(true, true); //hibernate 5.1.x版本
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
SchemaExport schemaExport = new SchemaExport();
schemaExport.create(EnumSet.of(TargetType.DATABASE), metadata);

注意:Hibernate 5.x的版本中,SchemaExport的用法不同于以前的版本,而网上的诸多资料都还停留在以前的3.x, 4.x的API

引用文献:http://blog.5ibc.net/p/49723.html