【问题标题】:java.lang.ClassNotFoundException if I use either hibernate-core 3.6.0 or hibernate-core 4.1.0java.lang.ClassNotFoundException 如果我使用 hibernate-core 3.6.0 或 hibernate-core 4.1.0
【发布时间】:2012-04-04 02:37:24
【问题描述】:

如何解决以下冲突?

  • 如果我使用的是 hibernate-core 3.6.0.Final

我遇到了一个异常:

Caused by: java.lang.ClassNotFoundException: org.hibernate.context.spi.CurrentSessionContext
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
  • 如果我使用的是 hibernate-core 4.1.0.Final

我遇到了一个异常:

Caused by: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
    at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:324)

我的项目的依赖:

my.project:jsf-spring-security:war:1.0.0
+- org.slf4j:slf4j-log4j12:jar:1.6.4:compile
|  +- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
|  \- (log4j:log4j:jar:1.2.16:compile - omitted for duplicate)
+- org.slf4j:slf4j-api:jar:1.6.4:compile
+- org.springframework:spring-core:jar:3.1.1.RELEASE:compile
|  +- org.springframework:spring-asm:jar:3.1.1.RELEASE:compile
|  \- commons-logging:commons-logging:jar:1.1.1:compile
+- org.springframework.ldap:spring-ldap:jar:all:1.3.1.RELEASE:compile
|  \- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
+- org.springframework:spring-webmvc:jar:3.1.1.RELEASE:compile
|  +- (org.springframework:spring-asm:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  +- org.springframework:spring-beans:jar:3.1.1.RELEASE:compile
|  |  \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  +- org.springframework:spring-context:jar:3.1.1.RELEASE:compile
|  |  +- (org.springframework:spring-aop:jar:3.1.1.RELEASE:compile - omitted for conflict with 3.0.6.RELEASE)
|  |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-expression:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  |  \- (org.springframework:spring-asm:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  +- org.springframework:spring-context-support:jar:3.1.1.RELEASE:compile
|  |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-context:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  |  \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  +- org.springframework:spring-expression:jar:3.1.1.RELEASE:compile
|  |  \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  \- org.springframework:spring-web:jar:3.1.1.RELEASE:compile
|     +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
|     +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework:spring-context:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|     \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
+- org.springframework:spring-jdbc:jar:3.1.1.RELEASE:compile
|  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  \- org.springframework:spring-tx:jar:3.1.1.RELEASE:compile
|     +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
|     +- (org.springframework:spring-aop:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|     +- (org.springframework:spring-context:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|     \- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
+- javax.servlet:jstl:jar:1.2:compile
+- javax.servlet.jsp.jstl:jstl-api:jar:1.2:provided
|  +- (javax.servlet:servlet-api:jar:2.5:provided - omitted for duplicate)
|  \- javax.servlet.jsp:jsp-api:jar:2.1:provided
+- log4j:log4j:jar:1.2.16:compile
+- org.aspectj:aspectjweaver:jar:1.6.10:compile
+- javax.servlet:servlet-api:jar:2.5:provided
+- org.apache.commons:com.springsource.org.apache.commons.httpclient:jar:3.1.0:compile
+- commons-lang:commons-lang:jar:2.4:compile
+- commons-dbcp:commons-dbcp:jar:1.4:compile
|  \- commons-pool:commons-pool:jar:1.5.4:compile
+- commons-io:commons-io:jar:1.4:compile
+- commons-fileupload:commons-fileupload:jar:1.2:compile
+- org.springframework.security:spring-security-taglibs:jar:3.1.0.RELEASE:compile
|  +- org.springframework.security:spring-security-web:jar:3.1.0.RELEASE:compile
|  |  +- (org.springframework:spring-tx:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  |  +- (org.springframework:spring-web:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  |  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-expression:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  |  +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  |  +- (org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-jdbc:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  |  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  |  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  |  \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework.security:spring-security-acl:jar:3.1.0.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework:spring-web:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework:spring-expression:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- org.springframework:spring-aop:jar:3.0.6.RELEASE:compile
|  |  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
|  |  +- (org.springframework:spring-asm:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  |  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  |  \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
+- org.springframework.security:spring-security-acl:jar:3.1.0.RELEASE:compile
|  +- (org.springframework:spring-tx:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- aopalliance:aopalliance:jar:1.0:compile
|  +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework:spring-jdbc:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
+- org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile
|  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
|  +- (org.springframework:spring-expression:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  \- org.springframework.security:spring-security-crypto:jar:3.1.0.RELEASE:compile
|     \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
+- org.springframework.security:spring-security-ldap:jar:3.1.0.RELEASE:compile
|  +- (org.springframework:spring-tx:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  \- org.springframework.ldap:spring-ldap-core:jar:1.3.1.RELEASE:compile
|     \- (commons-lang:commons-lang:jar:2.5:compile - omitted for conflict with 2.4)
+- org.springframework.security:spring-security-config:jar:3.1.0.RELEASE:compile
|  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
|  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
|  +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
|  \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 3.1.1.RELEASE)
+- junit:junit:jar:4.8.1:compile
+- net.sourceforge.jtds:jtds:jar:1.2.5:provided
+- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.2:compile
|  \- org.codehaus.jackson:jackson-core-asl:jar:1.8.2:compile
+- org.springframework:spring-test:jar:3.1.1.RELEASE:test
+- org.glassfish:javax.faces:jar:2.1.7:compile
+- org.primefaces:primefaces:jar:3.1.1:compile
+- org.glassfish:javax.annotation:jar:3.1.1:compile
+- org.hsqldb:hsqldb:jar:2.0.0:compile
+- com.oracle:ojdbc6:jar:11.2.0:compile
+- org.hibernate:hibernate-core:jar:4.1.0.Final:compile
|  +- commons-collections:commons-collections:jar:3.2.1:compile
|  +- antlr:antlr:jar:2.7.7:compile
|  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
|  +- dom4j:dom4j:jar:1.6.1:compile
|  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
|  +- (org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile - omitted for duplicate)
|  +- org.jboss.logging:jboss-logging:jar:3.1.0.CR2:compile
|  +- org.javassist:javassist:jar:3.15.0-GA:compile
|  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
|     \- (org.jboss.logging:jboss-logging:jar:3.1.0.CR2:compile - omitted for duplicate)
+- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
+- org.hibernate:hibernate-validator:jar:4.2.0.Final:compile
|  +- javax.validation:validation-api:jar:1.0.0.GA:compile
|  \- (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for conflict with 1.6.4)
+- org.springframework:spring-orm:jar:3.1.1.RELEASE:compile
|  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  +- (org.springframework:spring-jdbc:jar:3.1.1.RELEASE:compile - omitted for duplicate)
|  \- (org.springframework:spring-tx:jar:3.1.1.RELEASE:compile - omitted for duplicate)
\- javax.transaction:jta:jar:1.1:compile

【问题讨论】:

  • 是的。 Eclipse 3.7 和 Tomcat 7。
  • @Shagaan:“删除 Hibernate 4.0 并将 Hibernate 3.6 放在你的类路径中” - 但我提到在这种情况下我也会遇到异常。
  • @rapt:我知道,这只是为了表明你必须使用 Hibernate 3.6。现在你只有一个例外需要解决:D
  • @Shagaan:解决java.lang.ClassNotFoundException: org.hibernate.context.spi.CurrentSessionContext 问题的方法是什么?

标签: spring hibernate jsf maven dependencies


【解决方案1】:

rapt - 您使用 Hibernate 3.6 的错误是由于您仍然指的是

org.springframework.orm.hibernate4.LocalSessionFactoryBean

,使用

org.springframework.orm.hibernate3.LocalSessionFactoryBean

改为。

【讨论】:

    【解决方案2】:

    我已经设法在 Tomcat 7 上使用 Hibernate 4、Spring 3.1.0。

    使用

    1. org.springframework.orm.hibernate4.HibernateTransactionManager 交易经理
    2. org.springframework.orm.hibernate4.LocalSessionFactoryBean 用于会话工厂

    Spring 有新的包 org.springframework.orm.hibernate4.* 用于 休眠 4

    注意:Spring Hibernate 模板已从 Hibernate 4 支持中删除 (视为反模式)

    你可以看看Spring Hibernate 4 docs

    希望这会有所帮助!!!!

    【讨论】:

    • 我不明白应该在哪里配置 org.springframework.orm.hibernate4.HibernateTransactionManager 你能指定一个示例吗?我已经成功连接到休眠 3.6 与 4 有同样的问题。
    • +1 谢谢。我正在加载 hibernate3 版本,它正在寻找错误的休眠类。
    • HibernateTemplate 在任何 o.s.o.hiberatex 包中被弃用。 javadocs 只是建议您不要考虑将它用于新项目。 docs.spring.io/spring-framework/docs/current/javadoc-api/org/…
    猜你喜欢
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    相关资源
    最近更新 更多