我的hibernate应用程序工作正常但是当我升级到hibernate 4.4时,以下代码中的一个方法现在已被弃用。任何人都可以用新方法替换弃用的方法,提前谢谢。
Configuration configuration=new Configuration(); configuration=configuration.configure();
SessionFactory factory=configuration.buildSessionFactory(); //deprecated
Session session=factory.openSession();
Transaction transaction=session.beginTransaction();
答案 0 :(得分:1)
Hibernate documentation举了一个例子:
SessionFactory sf = new Configuration().configure().buildSessionFactory(
new StandardServiceRegistryBuilder().build() );
答案 1 :(得分:0)
将SessionFactory替换为以下内容:
public static SessionFactory configureSessionFactory() {
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
SessionFactory factory = configuration.buildSessionFactory(serviceRegistry);
return factory;
}