SessionFactory creation namingStrategy

While creating the SessionFactory in Hibernate I have faced lot's of issues. This is also one the exception which I have faced,

SessionFactory creation namingStrategy
Exception in thread "main" java.lang.ExceptionInInitializerError
       at com.jtb.util.HibernateUtil.buildSessionFactory(
       at com.jtb.util.HibernateUtil.getSessionFactory(
       at com.jtb.test.DeleteUser.main(
Caused by: java.lang.NoSuchFieldError: namingStrategy
       at org.hibernate.cfg.AnnotationConfiguration.reset(
       at org.hibernate.cfg.Configuration.<init>(
       at org.hibernate.cfg.Configuration.<init>(
       at org.hibernate.cfg.AnnotationConfiguration.<init>(
       at com.jtb.util.HibernateUtil.buildSessionFactory(
       ... 2 more

Here is the HibernateUtil class which I have placed the SessionFactory creation logic into it. Since, I am using Annotations, I have tried creating the SessionFactory by using AnnotationConfiguration.
package com.jtb.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {

 private static SessionFactory sessionFactory = null;

 private static synchronized SessionFactory buildSessionFactory() {
  try {
   return new AnnotationConfiguration().buildSessionFactory();
  } catch (Throwable ex) {
   System.err.println("SessionFactory creation failed." + ex);
   throw new ExceptionInInitializerError(ex);

 public static SessionFactory getSessionFactory() {
  return buildSessionFactory();

 public static void shutdown() {


The mistake what I have done is, I have used AnnotationConfiguration() to create the SessoinFactory instance. If we are using annotations also, it is fine to use Configuration() only.

Replace the below line
return new AnnotationConfiguration().buildSessionFactory();

return new Configuration().configure().buildSessionFactory();

Popular posts from this blog

Prime, Fibonacci and Factorial number with example in java

JNDI configuration for Tomcat 9 with Oracle