升级到 hibernate 4 和 spring 4 jars 但仍然得到 org.hibernate.engine.FilterDefinition classnotfoundexception

Posted

技术标签:

【中文标题】升级到 hibernate 4 和 spring 4 jars 但仍然得到 org.hibernate.engine.FilterDefinition classnotfoundexception【英文标题】:Upgraded to hibernate 4 and spring 4 jars but still getting org.hibernate.engine.FilterDefinition classnotfoundexception 【发布时间】:2016-05-23 11:14:05 【问题描述】:

我正在尝试升级到Hibernate 4.3.8Spring 4.1.6 版本。当我尝试初始化获取异常的上下文时,如下所示。

Caused by: java.lang.NoClassDefFoundError: [Lorg/hibernate/engine/FilterDefinition;
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.7.0_80]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2625) ~[na:1.7.0_80]
    at java.lang.Class.getDeclaredMethods(Class.java:1868) ~[na:1.7.0_80]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:571) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:488) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:501) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:474) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1065) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1038) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:860) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:790) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:542) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:436) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:412) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:186) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1105) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    ... 29 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.FilterDefinition
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720) ~[catalina.jar:7.0.59]
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) ~[catalina.jar:7.0.59]
    ... 49 common frames omitted

罐子列表

spring-aop-4.1.6.RELEASE.jar spring-data-jpa-1.2.0.RELEASE.jar, spring-security-web-4.0.1.RELEASE.jar,spring-aspects-4.1.6.RELEASE.jar,spring-expression-4.1.6.RELEASE.jar,spring-test-4.1.6.RELEASE.jar, spring-batch-core-2.1.7.RELEASE.jar、spring-jdbc-4.1.6.RELEASE.jar、spring-tx-4.1.6.RELEASE.jar、spring-batch-infrastructure-2.1.7.RELEASE。罐子,spring-orm-4.1.6.RELEASE.jar,spring-web-4.1.6.RELEASE.jar,spring-beans-4.1.6.RELEASE.jar,spring-oxm-4.1.6.RELEASE.jar, spring-webmvc-4.1.6.RELEASE.jar,spring-context-4.1.6.RELEASE.jar,spring-security-acl-4.0.1.RELEASE.jar,spring-webmvc-portlet-4.1.6.RELEASE。 jar,spring-context-support-4.1.6.RELEASE.jar,spring-security-config-4.0.1.RELEASE.jar,spring-ws-core-2.1.3.RELEASE.jar,spring-core-4.1。 6.RELEASE.jar,spring-security-core-4.0.1.RELEASE.jar,spring-xml-2.1.3.RELEASE.jar,spring-data-commons-core-1.4.0.RELEASE.jar,spring-安全标签库-4.0.1.RELEASE.jar hibernate-c3p0-4.3.8.Final.jar hibernate-envers-4.3.8.Final.jar hibernate-search-engine-4.5.3.Final.jar hibernate-commons-annotations-4.0.5.Final.jar hibernate-jpa-2.1-api-1.0.0.Final.jar hibernate-search-orm-4.5.3.Final.jar hibernate-core-4.3.8.Final.jar hibernate-jpamodelgen-4.3.8.Final.jar hibernate-validator-5.1.3.Final.jar hibernate-ehcache-4.3.8.Final.jar hibernate-search-4.5.3.Final.jar hibernate-entitymanager-4.3.8.Final.jar hibernate-search-analyzers-4.5.3.Final.jar

【问题讨论】:

compatability of spring 4.0.0 with hibernate 4.30的可能重复 【参考方案1】:

您的问题的解决方案

    您的类路径中可能缺少 hibernate-core-4.3.8.Final.jar。它有 FilterDefinition 类。

    如果您使用 Maven,请在您的 POM.xml 文件中添加此依赖项。

    <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-core</artifactId>
     <version>4.3.8.Final</version>
    </dependency>
    

【讨论】:

@Gowtham,请检查此异常是否仍然存在。 问题仍然存在。我已经为 sessionFactory 和 org.springframework.orm.hibernate4 添加了 hibernate-core-4.3.8.Final.jar 和 spring-orm-4.1.6.RELEASE.jar 和我的属性文件 org.springframework.orm.hibernate4.LocalSessionFactoryBean .HibernateTransactionManager 用于事务管理器。 @Gowtham,请确保您在类路径中添加了 SpringFramework 4.1.6 物料清单 (repo1.maven.org/maven2/org/springframework/spring-framework-bom/…) jar 文件。 是的,我已经在我的类路径中添加了所有依赖项。 您必须使用 LocalSessionFactoryBean 来与 Hibernate 集成,并且您必须使用 HibernateTransactionManager 进行事务处理。以下链接 (baeldung.com/hibernate-4-spring) 就是一个很好的例子

以上是关于升级到 hibernate 4 和 spring 4 jars 但仍然得到 org.hibernate.engine.FilterDefinition classnotfoundexception的主要内容,如果未能解决你的问题,请参考以下文章

GWT 开发模式 + Spring 3.1 + Hibernate 4.0.1 中的异常

支持 Hibernate 3.6.1 并升级到 5

spring 3 升级 spring 4.2.5遇到的问题

Hibernate 5.x和Spring Data 2.x:如何在服务保存方法中更新原始对象

将 Hibernate 3 升级到 Hibernate 4 的问题

Spring 4.1.6 和 Hibernate 3.2.2?