Hibernate (SessionFactory Configuration)

#1
SessionFactory sessionFactory =
new Configuration().configure().buildSessionFactory();

The above code gives me warning as buildSessionFactory is deprecated. I have Hibernate 4.0 version. I tried the below code:
Configuration config = new Configuration();
config.configure();
ServiceRegistry serviceRegistry= new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
SessionFactory sessionfactory = config.buildSessionFactory(serviceRegistry);
Session session = sessionfactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();

it still doesnt work, any suggeestion.
 
Top