2015-09-09 280 views
4

我想要使用休眠5的Java EE在Tomcat 7,我收到此錯誤:如何解決Hibernate 5中的AbstractMethodError?

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任何廣口瓶。

這是我的依賴關係的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。

的休眠似乎在日誌中啓動的權利,但不創造實體管理器。

如何解決這個問題?當你有你用來編譯罐子,而服務器運行的代碼引用的一個之間的不兼容性

回答

3

AbstractMethodError被拋出。如果某些類的定義,因爲發生了不相容改變只能出現在運行時該錯誤;當應用程序試圖調用一個抽象方法

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

」拋出該異常通常情況下,該錯誤是由編譯器捕獲。當前正在執行的方法,最後編譯。

這可能是由於休眠的搜索&休眠實體管理器的版本

Hibernate Search的似乎是使用Hibernate公地的註解4.0.5最終

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

Hibernate的實體管理器好像是用hibernate-commons-annotation-5.0.0.Final

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

檢查你的依賴層次選項卡中的pom.xml eclipse找出正在使用哪個精確的jar版本。用於排除不兼容的版本。通常這是由pom自動完成的。您也可以檢查您的WEB-INF/lib文件夾以查看正在下載的jar包。

我也看到你使用這個罐子。如果您更好地使用tomcat 7來代替它,並且將其作用域「提供」,因爲在運行時,Web應用程序引用tomcat servlet api jar。

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

如果我使用alpha版本,可能會解決這個問題嗎? http://mvnrepository.com/artifact/org.hibernate/hibernate-search-engine/5.5.0.Alpha1我對「測試」版本有點恐懼,這可能是一個解決方案嗎?而且我使用的是Lucene 5.3.0,hibernate-search使用lucene 5.2.1,是否會導致另一個衝突? –

+1

問題解決了,我改變了hibernate-search和lucene-core的版本,並且工作。謝謝 –

相關問題