java.lang.NoSuchMethodError: org.hibernate.Session.getNamedQuery(Ljava/lang/String;)Lorg/hibernate/query/Query;

Spring JIRA | Steve Storey | 8 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    https://github.com/spring-projects/spring-framework/blob/master/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java#L958 attempts to be compatible with Hibernate 5.x, but because it's compiled against 5.2, the compiler then requires that the runtime method return a org.hibernate.query.Query instance, and thus when running with standard Spring Boot 1.4 versions, you get: {code} java.lang.NoSuchMethodError: org.hibernate.Session.getNamedQuery(Ljava/lang/String;)Lorg/hibernate/query/Query; at org.springframework.orm.hibernate5.HibernateTemplate$32.doInHibernate(HibernateTemplate.java:958) at org.springframework.orm.hibernate5.HibernateTemplate$32.doInHibernate(HibernateTemplate.java:954) at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:356) at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:323) at org.springframework.orm.hibernate5.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:954) at example.HibernateTemplateBugTest.testFindByNamedQuery(HibernateTemplateBugTest.java:28) {code} in the attached reproduction test when run with simply {code} mvn clean test {code} If however, you override the standard Hibernate version to 5.2.2 then the test succeeds by running {code} mvn -Dhibernate.version=5.2.2.Final clean test {code}

    Spring JIRA | 8 months ago | Steve Storey
    java.lang.NoSuchMethodError: org.hibernate.Session.getNamedQuery(Ljava/lang/String;)Lorg/hibernate/query/Query;

    Root Cause Analysis

    1. java.lang.NoSuchMethodError

      org.hibernate.Session.getNamedQuery(Ljava/lang/String;)Lorg/hibernate/query/Query;

      at org.springframework.orm.hibernate5.HibernateTemplate$32.doInHibernate()
    2. org.springframework.orm
      HibernateTemplate.findByNamedQuery
      1. org.springframework.orm.hibernate5.HibernateTemplate$32.doInHibernate(HibernateTemplate.java:958)
      2. org.springframework.orm.hibernate5.HibernateTemplate$32.doInHibernate(HibernateTemplate.java:954)
      3. org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:356)
      4. org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:323)
      5. org.springframework.orm.hibernate5.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:954)
      5 frames
    3. example
      HibernateTemplateBugTest.testFindByNamedQuery
      1. example.HibernateTemplateBugTest.testFindByNamedQuery(HibernateTemplateBugTest.java:28)
      1 frame