Hibernate 4 升级到 Hibernate 5 的时候 SessionFactory 不能使
作者:互联网
在 Hibernate 4 升级到 5 的时候老的 sessionFactory 出现错误。
public static SessionFactory initSession() { Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); return sessionFactory; }
你可以使用下面的代码来在 Hibernate 5 中初始化:
public static SessionFactory initSession() { Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new StandardServiceRegistryBuilder().configure().build(); Metadata metadata = new MetadataSources(serviceRegistry).getMetadataBuilder().build(); sessionFactory = metadata.getSessionFactoryBuilder().build(); return sessionFactory; }
https://blog.ossez.com/archives/3065
标签:升级,Hibernate,Configuration,sessionFactory,SessionFactory,build,new,configuration 来源: https://blog.51cto.com/ossez/2442494