Hibernate – The type AnnotationConfiguration is deprecated

Problem

Working with Hibernate 3.6, noticed the previous “org.hibernate.cfg.AnnotationConfiguration“, is marked as “deprecated“.

Code snippets …

import org.hibernate.cfg.AnnotationConfiguration;
//...
private static SessionFactory buildSessionFactory() {
	try {
 
		return new AnnotationConfiguration().configure().buildSessionFactory();
 
	} catch (Throwable ex) {
 
		System.err.println("Initial SessionFactory creation failed." + ex);
		throw new ExceptionInInitializerError(ex);
	}
}

The code is still working, just keep displaying the deprecated warning message, is there any replacement for “AnnotationConfiguration” ?

Solution

In Hibernate 3.6, “org.hibernate.cfg.AnnotationConfiguration” is deprecated, and all its functionality has been moved to “org.hibernate.cfg.Configuration“.

So , you can safely replace your “AnnotationConfiguration” with “Configuration” class.

Code snippets …

import org.hibernate.cfg.Configuration;
//...
private static SessionFactory buildSessionFactory() {
	try {
 
		return new Configuration().configure().buildSessionFactory();
 
	} catch (Throwable ex) {
 
		System.err.println("Initial SessionFactory creation failed." + ex);
		throw new ExceptionInInitializerError(ex);
	}
}

References

  1. http://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/cfg/AnnotationConfiguration.html
  2. http://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/cfg/Configuration.html
Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments