Here is my HibernateUtil.java file… When dealing with hibernate framework, it gave the @depracated error and I had to find correct “default” HibernateUtil file.

This is what works for my version:

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class HibernateUtil {

 private static SessionFactory sessionFactory;
 private static ServiceRegistry serviceRegistry;

 static {
 try {
// Configuration configuration = new Configuration();
 Configuration configuration = new Configuration().configure();

 serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
 sessionFactory = configuration.buildSessionFactory(serviceRegistry);
 } catch (HibernateException he) {
 System.err.println("Error creating Session: " + he);
 throw new ExceptionInInitializerError(he);

 public static SessionFactory getSessionFactory() {
 return sessionFactory;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s