NoSuchMethodError:org.hibernate.SessionFactory.getCurrentSession()

信使:

您好,

我收到了一个非常奇怪的错误:

java.lang.NoSuchMethodError: org.hibernate.SessionFactory.getCurrentSession()Lor
g/hibernate/classic/Session;
        at org.cometd.hibernate.util.HibernateUtil.getSessionFactory(HibernateUt
il.java:29)
        at org.cometd.hibernate.util.HibernateUtil.getSession(HibernateUtil.java
:54)

但是此方法存在于JavaDocs的SessionFactory类中!
我的Eclipse在自动完成中也向我展示了它。
但是其他一些方法,例如openSession()或closeSession()也可以正常工作。
问题可以在哪里隐藏?
我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">



    <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <overlays>
                        <overlay />
                        <overlay>
                            <groupId>org.cometd.javascript</groupId>
                            <artifactId>cometd-javascript-dojo</artifactId>
                        </overlay>
                    </overlays>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.24</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webAppConfig>
                        <contextPath>/sample</contextPath>
                    </webAppConfig>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>cometd-api</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.cometd.javascript</groupId>
            <artifactId>cometd-javascript-dojo</artifactId>
            <version>1.1.2</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>cometd-java-server</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.3.2.GA</version>
            <!--<version>3.6.0.Final</version>-->
        </dependency>               
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.4.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>3.1.0.GA</version>
        </dependency>


        <!-- log4j -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.10</version>
            <!-- <scope>runtime</scope>  -->
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.10</version>
            <!-- <scope>runtime</scope>  -->
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.5.10</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <!-- <scope>runtime</scope>  -->
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.9</version>
        </dependency>

        <dependency>
            <groupId>org.jmock</groupId>
            <artifactId>jmock-junit4</artifactId>
            <version>2.5.1</version>
        </dependency>

        <dependency> 
            <groupId>org.quartz-scheduler</groupId> 
            <artifactId>quartz</artifactId>
            <version>1.8.2</version> 
        </dependency> 

        <!-- Hibernate framework -->
    <dependency>
        <groupId>hibernate</groupId>
        <artifactId>hibernate3</artifactId>
        <version>3.2.3.GA</version>
    </dependency>

    <!-- Hibernate annotation -->
    <dependency>
        <groupId>hibernate-annotations</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.3.0.GA</version>
    </dependency>

    <dependency>
        <groupId>hibernate-commons-annotations</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.0.0.GA</version>
    </dependency>



    <!-- Hibernate library dependecy start -->
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>

    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>

    <dependency>
        <groupId>antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>2.7.7</version>
    </dependency>

    <dependency>
    <groupId>javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.5.0.GA</version>
</dependency>

    </dependencies>

    <repositories>
        <repository>
            <id>JBoss repository</id>
            <url>http://repository.jboss.com/maven2/</url>
        </repository>
    </repositories>

</project>

PS的代码是

org.hibernate.SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

org.hibernate.Session session = sessionFactory.getCurrentSession();
马丁·阿尔杰森(Martin Algesten):

我认为这可能归结为classpath上的多个休眠版本。这里看起来太多了...

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.2.GA</version>
        <!--<version>3.6.0.Final</version>-->
    </dependency>               
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>3.1.0.GA</version>
    </dependency>

....

<dependency>
    <groupId>hibernate</groupId>
    <artifactId>hibernate3</artifactId>
    <version>3.2.3.GA</version>
</dependency>

<!-- Hibernate annotation -->
<dependency>
    <groupId>hibernate-annotations</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.3.0.GA</version>
</dependency>

<dependency>
    <groupId>hibernate-commons-annotations</groupId>
    <artifactId>hibernate-commons-annotations</artifactId>
    <version>3.0.0.GA</version>
</dependency>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring MVC的:没有合格类型的豆[org.hibernate.SessionFactory实例]发现依赖

需要类型的bean的org.hibernate.SessionFactory实例“不能被发现

Hibernate SessionFactory与JPA EntityManagerFactory

使用hibernate sessionFactory还是JPAEntityManager?

Spring 3.1,Hibernate 4,SessionFactory

Hibernate的Sessionfactory.getCurrentSession()和SessionFactory.openSession()的区别

java.lang.NoSuchMethodError:org.hibernate.SessionFactory.openSession()Lorg / hibernate / classic / Session

Hibernate初始SessionFactory创建失败

春季引导。找不到类型为“ org.hibernate.SessionFactory”的bean

使用_sessionFactory.getCurrentSession()检索用户会话中的当前用户ID。冬眠的

在Hibernate中使用SessionFactory.getCurrentSession()时获取Connection对象

正确配置以模拟Hibernate的sessionFactory.getCurrentSession()

Micronaut数据-没有类型为[org.hibernate.SessionFactory]的bean

通过“ sessionFactory”的不满意的依赖;没有可用的'org.hibernate.SessionFactory'类型的合格bean

Hibernate SessionFactory与Spring LocalSessionFactoryBean

导入错误:Org.Hibernate.SessionFactory等

由于在org.hibernate.internal.util.ConfigHelper.getResourceAsStream上的java.lang.NullPointerException,Hibernate 4.3.5 SessionFactory创建失败

未为类型SessionFactory定义方法getCurrentSession()

Hibernate OpenSession()与GetCurrentSession()

初始SessionFactory创建失败.org.hibernate.HibernateException:缺少列

Hibernate + Spring SessionFactory配置

休眠:sessionFactory.openSession()VS sessionFactory.getCurrentSession()

获取文件路径-Hibernate SessionFactory

Spring + Hibernate:sessionFactory.getCurrentSession()导致NullPointerException

BeanInstantiationException:无法实例化 [org.hibernate.SessionFactory]:涉及包含 bean 的循环引用

启动 Micronaut 服务器时出错:无法加载 Bean 定义 [org.hibernate.SessionFactory]

Hibernate SessionFactory,动态设置TransactionIsolationLevel

无法实例化 [org.springframework.orm.hibernate5.LocalSessionFactoryBean]:工厂方法“sessionFactory”抛出异常

无法建立 Hibernate SessionFactory;嵌套异常是 org.hibernate.MappingException:无法实例化 id 生成器