我使用的是hibernate 3.2.5.GA,当调用SessionFactory
的openSession
时,它返回Session
org.hibernate.classic.Session 类型的对象:
public org.hibernate.classic.Session openSession() throws HibernateException;
我也使用Spring Batch 2.2.7.RELEASE,在HibernateItemReaderHelper
中设置SessionFacotry
时,时抛出异常openSession
被调用,因为它需要 Session
类型:org.hibernate.Session
:
java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
有人知道这个问题的解决办法吗?
附注我无法升级 Hibernate。
最佳答案
奇怪的是,他们在 SessionFactory 中使用 org.hibernate.classic.Session 实现,即使在版本 3 到版本 4 之后,看看两者是如何可用的( org.hibernate.classic.Session 和 org.hibernate.Session )版本 3。您可能知道 spring classic 用于与 hibernate 2.1 兼容,从 hibernate 3 开始已弃用。
建议
你不应该使用HibernateItemReaderHelper,因为它是一个Spring内部类。它是在 Spring Batch 2.2.7 中引入的。
解决方案
我查看了所有可用的代码 item readers但他们使用了新的 org.hibernate.Session。 在此版本中无法解决此问题。
- 如果您无法更改 hibernate 版本,请将 Spring Batch 版本更改为较早的版本,并选择其项目读取器之一。
- 如果您也无法做到这一点,请构建自定义项目阅读器。
这是link浏览 Spring Batch 源代码并检查正在使用哪个 Session 版本,当您开始在 org.springframework.batch.item 包下的各种 Spring Batch 版本中查找项目读取器时。
关于java - SessionFactory调用openSession抛出noSuchMethoderror异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30528615/