37

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?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Tim
  • 13,228
  • 36
  • 108
  • 159

4 Answers4

40

"All functionality has been moved to Configuration": http://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/cfg/AnnotationConfiguration.html

And here is Configuration:

http://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/cfg/Configuration.html

Stas
  • 1,707
  • 15
  • 25
  • 13
    Why, then, does the application not start up with Configuration, but gives a MappingException: An AnnotationConfiguration instance is required to use – orbfish Feb 09 '11 at 22:01
  • 2
    That's the same error that I get when trying to use this with Hiberate 4.0.1 – Omertron Feb 20 '12 at 10:23
5

Just do this

import org.hibernate.cfg.Configuration;

and then change your code for this

sessionFactory = new Configuration().configure("/hib.cfg.xml").buildSessionFactory(); 
fuelusumar
  • 797
  • 8
  • 15
2

I use this code:

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

sessionFactory = new Configuration().configure().buildSessionFactory(serviceRegistry);
Omar Vargas
  • 53
  • 1
  • 3
Demven Weir
  • 807
  • 7
  • 6
1

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();
Rishi Arora
  • 1,713
  • 3
  • 16
  • 31