0

I am new in Hibernate and I am studying this ORM framework reading this article: http://www.tutorialspoint.com/hibernate/hibernate_examples.htm

I have read all the previous Hibernate tutorial of this site and until now it is all pretty clear for me.

The only "problem" is that I am not using Hibernate 3.6.4-Final (as is used in this tutorials series) but I am using the last Hibernate 4.1.9-Final version.

I have implement this example and work well but Eclipse say me that an instruction of the main class ManageEmployee are deprechated.

The deprecated instruction is the calling of buildSessionFactory() following one:

factory = new Configuration().configure().buildSessionFactory();`

How can I replace it to create a new factory that is not deprecated?

Tnx

Andrea

1

1 Answer 1

2

In Hibernate 4, buildSessionFactory( ) is deprecated. This example contains code which you can use in spite of buildSessionFactory ().

private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;

private static SessionFactory configureSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration();
    configuration.configure();
    serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();        
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    return sessionFactory;
}

You can get more details at Hibernate 4 Simple Example

1
  • 2
    org.hibernate.service.ServiceRegistryBuilder is also deprecated! Commented Jan 15, 2014 at 15:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.