如何在Hibernate 5中解决AbstractMethodError? [英] How to solve AbstractMethodError in Hibernate 5?

查看:59
本文介绍了如何在Hibernate 5中解决AbstractMethodError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Java EE中的休眠5与tomcat 7一起使用,并且出现此错误:

i'm trying to use the hibernate 5 in Java EE with tomcat 7, and i'm getting this error:

java.lang.AbstractMethodError
org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:278)
org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:802)
org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
controller.dao.GenericDAO.<clinit>(GenericDAO.java:28)
com.mycompany.mazkrest.UsuarioResource.login(UsuarioResource.java:89)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:483)
org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:309)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
org.glassfish.jersey.internal.Errors.process(Errors.java:315)
org.glassfish.jersey.internal.Errors.process(Errors.java:297)
org.glassfish.jersey.internal.Errors.process(Errors.java:267)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:292)
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1139)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:460)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

我正在使用JPA 2.1,已经删除了所有旧的jpa版本的jar.

I'm using JPA 2.1, I've deleted any jars of old jpa versions.

这是我对pom.xml的依赖:

Here is my dependencies in pom.xml:

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <!-- <version>${jersey.version}</version>-->
        <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
        <!-- artifactId>jersey-container-servlet</artifactId -->
    </dependency>

    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
    </dependency>

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

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.6.1</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.6.1</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
        <version>2.6.1</version>
    </dependency>

    <dependency>
        <groupId>com.voodoodyne.jackson.jsog</groupId>
        <artifactId>jackson-jsog</artifactId>
        <version>1.1</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.6.1</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <!--  <version>${jersey.version}</version>-->
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search</artifactId>
        <version>5.3.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
        <version>5.3.0</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.0.1.Final</version>
    </dependency>

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <type>jar</type>
    </dependency>
</dependencies>

当我第二次执行引发异常的代码时,我收到了NoDefClassFoundError.

When i execute the code that throws the exception for the second time, i get a NoDefClassFoundError.

休眠状态似乎在日志中启动,但是没有创建实体管理器.

The hibernate seems booting right in the log, but isn't creating the entity manager.

如何解决这个问题?

推荐答案

当您用来编译的jar与服务器运行代码时引用的jar不兼容时,将引发AbstractMethodError.

AbstractMethodError is thrown when you have incompatibility between the jar you used to compile and the one referred while server is running the code.

http://docs.oracle.com/javase/7/docs/api/java/lang/AbstractMethodError.html

当应用程序尝试调用抽象方法时引发.通常,此错误由编译器捕获;仅当自从当前执行的方法上次编译以来某些类的定义发生不兼容的更改时,才在运行时发生此错误

"Thrown when an application tries to call an abstract method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.

这可能是由于hibernate-search&休眠实体管理器

It could be due to the versions of hibernate-search & hibernate-entity-manager

休眠搜索似乎使用的是hibernate-commons-annotations 4.0.5 final

hibernate search seems to be using hibernate-commons-annotations 4.0.5 final

http://mvnrepository.com/artifact/org.hibernate/hibernate-search-engine/5.3.0.Final

Hibernate实体管理器似乎正在使用hibernate-commons-annotation-5.0.0.Final

Hibernate entity manager seems to be using hibernate-commons-annotation-5.0.0.Final

http://mvnrepository.com/artifact/org. hibernate/hibernate-entitymanager/5.0.1.Final

在eclipse中检查Dependency Hierarchy选项卡中的pom.xml,以了解使用了哪个确切的jar版本.用于排除不兼容的版本.通常,这是由pom自动完成的.您也可以检查WEB-INF/lib文件夹以查看正在下载的jar.

Check your Dependency Hierarchy tab for pom.xml in eclipse to find out which exact jar version is being used. Use to exclude incompatible versions. usually this is done automatically by pom. You could also check your WEB-INF/lib folder to see what are jars are being downloaded.

我还看到您正在使用此罐子.如果您使用的是tomcat 7,则最好改用它,并提供其作用域,因为在运行时Web应用程序引用了tomcat servlet api jar.

Also I see that you are using this jar. If you are using tomcat 7 better to use this instead and have its scope "provided" because at runtime the web app refers to the tomcat servlet api jar.

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-servlet-api</artifactId>
    <version>7.0.21</version>
    <scope>provided</scope>
    </dependency>

这篇关于如何在Hibernate 5中解决AbstractMethodError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆