SchemaExport方法有一条删除线,怎么解决
package entity; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.tool.hbm2ddl.SchemaExport; import org.junit.Test; public class TestStudents { @Test public void testSchemaExport(){ //创建配置对象 Configuration config = new Configuration().configure(); //创建服务注册对象 //ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build(); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build(); //创建sessionFactory SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry); //创建session对象 Session session = sessionFactory.getCurrentSession(); //创建SchemaExport对象 MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( serviceRegistry ).buildMetadata(); new SchemaExport(metadata).create(true, true); } }
hibernate 5.0把创建SchemaExport那要跟最下面那个一样,希望对你有帮助!
换一个HIbernate版本
方法上有一条删除线,说明这个方法已经过时了,不再用了。你这个应该是老版本hibernate的方法。我用最新的hibernate只要把SessionFactory创建出来之后,就会自动在数据库中生成对应的表。