HibernateTemplate is throwing java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode() ― Spring4.2.6, Hibernate5.2

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

I have looked around similar postings with SessionFactory and missing Main(). My problem is not related to them. Not sure if any jar is a mismatch. I am trying a sample Spring4.2.6 with Hibernate5.2 code using JDK8 and getting this exception:

Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode; at org.springframework.orm.hibernate5.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1125) at org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:619) at org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:616) at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:341) at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:309) at org.springframework.orm.hibernate5.HibernateTemplate.save(HibernateTemplate.java:616) at com.nougain.springtraining.hibernate.CustomerDAOImpl.save(CustomerDAOImpl.java:37) at com.nougain.springtraining.hibernate.Client_SpringHibernate.testSpringHibernate(Client_SpringHibernate.java:29) at com.nougain.springtraining.hibernate.Client_SpringHibernate.main(Client_SpringHibernate.java:12) 

Below is the jar files I am using:

DAOImpl code snippet:

import org.springframework.stereotype.Component; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.hibernate5.HibernateTemplate;  @Component("customerDAO") public class CustomerDAOImpl implements CustomerDAO {     @Autowired     private HibernateTemplate hibernateTemplate;      public CustomerDAOImpl() {         System.out.println("___Created CustomerDAOImpl() object");     }      @Override     public void save(Customer c) {         hibernateTemplate.save(c);     }         ... } 

My Configuration file looks like:

bin/connection.propertiestruetruetrue                 org.hibernate.transaction.JDBCTransactionFactory             createCustomer.hbm.xml

Thanks for your help.

回答1:

I still couldn't make Spring 4.2.6 to work with Hibernate 5.2.0 (which was just released some days ago), although the error I got is different. I'm still using Hibernate 5.1.0 then.

Note that on Hibernate 5.1.0 you need two jars: hibernate-core and hibernate-entitymanager.

[EDIT]Spring 4.2.6 lists Hibernate 5.0.9 as optional dependency so you probably should stick with that version, although 5.1.0 is working fine for me.

Spring 4.2.6 probably isn't compatible with Hibernate 5.2.0 as this version of hibernate brought some big changes, merging hibernate-core with hibernate-entitymanager and hibernate-java8.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!