How to resolve NoSuchFieldError : namingStrategy in Hibernate

When configuring and using Hibernate in your application you might have surely came across the error which says java.lang.NoSuchFieldError : namingStrategy. The full stack trace of the error would be of the form:

Exception in thread “main” 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.codippa.Main.main(

and the code which is generating this error would be as given below :

AnnotationConfiguration cfg = new AnnotationConfiguration();
SessionFactory sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.getCurrentSession();

Solution :

There may be multiple solutions of this error.

      1. Try replacing this line :
        AnnotationConfiguration cfg = new AnnotationConfiguration();

        with this

        Configuration cfg = new Configuration();

        Reason : Starting Hibernate v3.6, the class org.hibernate.cfg.AnnotationConfiguration has been Deprecated. All its functionality has been moved to org.hibernate.cfg.Configurationclass. So if you are using the above code, then chances are that the Hibernate version being utilized in your application is 3.6 or above. Refer this link.

      2. Check your dependencies. You might have two different versions of Hibernate. For example, if you are using Maven, then you may find something like below in your pom.xml.
      3. Try removing the slf4j dependency (if you have) from your build path. If you are using Maven, then modify your Hibernate dependency to :

        If the build tool is Gradle then something like that given below might help :

        dependencies {
          compile ('org.hibernate:hibernate:3.1') {
          exclude group: "org.slf4j", name: "slf4j-log4j12"

      Did any of the above methods resolve your error ? Wonderful !!! Let others also resolve this problem by your sharing


This Post Has 2 Comments

  1. There are many solutions available for this problem but none of them had the reasons behind those solutions. Now I understand why those solutions work. Thanks

    1. Thanks Swati…

Share your thoughts !!

Close Menu

Never Miss an article !

Get the new post delivered straight into your inbox, enter your email and hit the button

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

codippa will use the information you provide on this form to be in touch with you and to provide updates and marketing.