Hibernate - Annotationconfiguration Deprecated

I am using Hibernate in version 3.6.0 and the AnnotationConfiguration is marked as deprecated.

Here is the the line in my HibernateUtil.java class:

sessionFactory = new AnnotationConfiguration().configure("/hib.cfg.xml").buildSessionFactory();

What's the replacement for AnnotationConfiguration?

4 Answers

"All functionality has been moved to Configuration":

And here is Configuration:

2

Just do this

import org.hibernate.cfg.Configuration;

and then change your code for this

sessionFactory = new Configuration().configure("/hib.cfg.xml").buildSessionFactory(); 

I use this code:

Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();

sessionFactory = new Configuration().configure().buildSessionFactory(serviceRegistry);

yes it is working for me-

Configuration cfg=new Configuration();
    cfg.configure();

    ServiceRegistry serviceregistry=new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();


    Session session=cfg.configure().buildSessionFactory(serviceregistry).openSession();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest