Hibernate Error: NoSuchMethodError

Diskutiere Hibernate Error: NoSuchMethodError im Datenbankprogrammierung Bereich.
D

DirtyBit

Hallo zusammen,
ich möchte via Hibernate eine Postgres Datenbank nutzen, erhalte allerdings immer wieder folgenden Fehler:
java.lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.XMLContext.<init>(Lorg/hibernate/boot/spi/ClassLoaderAccess;)V

Hier mehr Informationen:
XML:
        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.3.Final</version>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

12214

XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="[URL]http://xmlns.jcp.org/xml/ns/persistence[/URL]"
    xmlns:xsi="[URL]http://www.w3.org/2001/XMLSchema-instance[/URL]" version="2.1"
    xsi:schemaLocation="[URL]http://xmlns.jcp.org/xml/ns/persistence[/URL] [URL]http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd[/URL]">
    <persistence-unit name="postgres">
        <description>Hibernate Tips</description>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>

        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect" />
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/postgres" />
            <property name="javax.persistence.jdbc.user" value="postgres" />
            <property name="javax.persistence.jdbc.password" value="123" />
        </properties>
    </persistence-unit>
</persistence>

Java:
 package org.isse.sopro;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class HibernateUtil {
   
    private static EntityManager entityManager;
   
    private HibernateUtil() {
    }
   
    public static EntityManager getEntityManager() {
        if(entityManager == null) {
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("postgres");
            entityManager = emf.createEntityManager();
        }
       
        return entityManager;
    }
}

Code:
java.lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.XMLContext.<init>(Lorg/hibernate/boot/spi/ClassLoaderAccess;)V
    at org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.<init>(JPAMetadataProvider.java:87)
    at org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.<init>(JPAMetadataProvider.java:81)
    at org.hibernate.boot.internal.BootstrapContextImpl.generateHcannReflectionManager(BootstrapContextImpl.java:315)
    at org.hibernate.boot.internal.BootstrapContextImpl.<init>(BootstrapContextImpl.java:89)
    at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:123)
    at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:136)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:218)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:174)
    at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:76)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:171)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:119)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at org.isse.sopro.HibernateUtil.getEntityManager(HibernateUtil.java:16)
    at org.isse.sopro.UserContainer.instance(UserContainer.java:19)
    at org.isse.sopro.LoginServlet.doPost(LoginServlet.java:47)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:835)

Danke im voraus an jeden der sich Zeit nimmt =)
 
H

httpdigest

Solche Exceptions kommen meist, wenn zueinander inkompatible Libraries verwendet werden. Z.B. eine hibernate-core mit einer dazu inkompatiblen hibernate-annotations. Check mal deinen gesamten Maven dependency tree (via `mvn dependency:tree`), ob du (oder andere Libraries) unterschiedliche Versionen von Hibernate Libraries verwendest.
 
D

DirtyBit

Danke für die Antwort. Also ich hab in Eclipse mal in der pom.xml die Hierarchie geöffnet. Da konnte ich nichts feststellen. Ich habe auch nur Hibernate core eingebunden.
12215
12216
 
M

mrBrown

Zeig mal die Ausgabe von mvn dependency:tree, das ist hier deutlich praktischer als ein Screenshot :)
 
D

DirtyBit

Vielen Dank an alle. Also es war tatsächlich ein Problem mit den Maven Dependencies. Ich hab mein Maven Build erneuert und jetzt funktioniert alles :)
 
Thema: 

Hibernate Error: NoSuchMethodError

Passende Stellenanzeigen aus deiner Region:
Anzeige

Neue Themen

Anzeige

Anzeige
Oben