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:
install maven-compiler-plugin 1.5 1.5 maven-war-plugin org.cometd.javascript cometd-javascript-dojo org.mortbay.jetty maven-jetty-plugin 6.1.24 10 /sample javax.servlet servlet-api 2.5 provided org.cometd.java cometd-api 1.1.2 org.cometd.javascript cometd-javascript-dojo 1.1.2 war org.cometd.java cometd-java-server 1.1.2 org.hibernate hibernate-core 3.3.2.GA <!--3.6.0.Final--> org.hibernate hibernate-annotations 3.4.0.GA org.hibernate hibernate-validator 3.1.0.GA org.slf4j slf4j-log4j12 1.5.10 <!-- runtime --> org.slf4j slf4j-log4j12 1.5.10 <!-- runtime --> org.slf4j slf4j-api 1.5.10 log4j log4j 1.2.15 javax.mail mail javax.jms jms com.sun.jdmk jmxtools com.sun.jmx jmxri <!-- runtime --> mysql mysql-connector-java 5.1.9 org.jmock jmock-junit4 2.5.1 org.quartz-scheduler quartz 1.8.2 hibernate hibernate3 3.2.3.GA hibernate-annotations hibernate-annotations 3.3.0.GA hibernate-commons-annotations hibernate-commons-annotations 3.0.0.GA dom4j dom4j 1.6.1 commons-collections commons-collections 3.2.1 antlr antlr 2.7.7 javassist javassist 3.5.0.GA JBoss repository http://repository.jboss.com/maven2/
PS的代码是
org.hibernate.SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); org.hibernate.Session session = sessionFactory.getCurrentSession();
我认为它可能归结为类路径上的多个hibernate版本。 这里看起来太多了……
org.hibernate hibernate-core 3.3.2.GA org.hibernate hibernate-annotations 3.4.0.GA org.hibernate hibernate-validator 3.1.0.GA .... hibernate hibernate3 3.2.3.GA hibernate-annotations hibernate-annotations 3.3.0.GA hibernate-commons-annotations hibernate-commons-annotations 3.0.0.GA
对于Hibernate 4.1.1我添加了
org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory
到hibernate.config.xml
对于Hibernate 3,我添加了
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
它解决了我的问题
- Hibernate – ClassNotFoundException:com.mysql.jdbc.Driver
- Hibernate参数化sql查询慢和活动的oracle会话
- 在Spring Framework 3.0中使用Hibernate和Jdbc
- 为什么spring / hibernate只读数据库事务比read-write运行得慢?
- 如何使用JPA连接到多个数据库?
- @ElementCollection with Map 其中Entity是Embeddable的一个字段
- 如何使用JPA(Hibernate)创建与同一实体的关系?
- 如何在运行时在Hibernate中创建数据库?
- JPA / Hibernate:CriteriaBuilder – 如何使用关系对象创建查询?