Home > front end >  Spigot/Bungeecord Hibernate - Invalid logger interface org.hibernate.internal.CoreMessageLogger
Spigot/Bungeecord Hibernate - Invalid logger interface org.hibernate.internal.CoreMessageLogger

Time:08-19

I tried using Hibernate ORM to handle my BungeeCord database mappings. I've used it before and had no problems doing so.

Now I revisited Minecraft programming and could not get Hibernate running.

My pom.xml is:

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>io.jakobi</groupId>
    <artifactId>sessionutil</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>17</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>oss.sonatype.org</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </repository>
        <repository>
            <id>maven.enginehub.org</id>
            <url>https://maven.enginehub.org/repo/</url>
        </repository>
        <repository>
            <id>repo.spongepowered.org</id>
            <url>https://repo.spongepowered.org/maven/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>net.md-5</groupId>
            <artifactId>bungeecord-api</artifactId>
            <version>1.19-R0.1-SNAPSHOT</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>net.md-5</groupId>
            <artifactId>bungeecord-api</artifactId>
            <version>1.19-R0.1-SNAPSHOT</version>
            <type>javadoc</type>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.1.2.Final</version>
            <scope>compile</scope>
        </dependency>

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

        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>23.0.0</version>
        </dependency>
    </dependencies>

    <build>
        <defaultGoal>clean install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <minimizeJar>true</minimizeJar>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <dependencies>
                    <dependency>
                        <groupId>org.junit.platform</groupId>
                        <artifactId>junit-platform-surefire-provider</artifactId>
                        <version>1.0.1</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
</project>

And my main is:

package io.jakobi.sessionutil;

import io.jakobi.sessionutil.database.entity.Action;
import io.jakobi.sessionutil.database.entity.Session;
import io.jakobi.sessionutil.database.repository.ActionRepository;
import io.jakobi.sessionutil.database.repository.SessionRepository;
import io.jakobi.sessionutil.listener.PlayerChatListener;
import io.jakobi.sessionutil.listener.PlayerJoinListener;
import io.jakobi.sessionutil.listener.PlayerQuitListener;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
import org.hibernate.Hibernate;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.internal.CoreMessageLogger;

import java.io.File;

public class SessionUtil extends Plugin {

    private static final String HIBERNATE_CONFIG_FILE_NAME = "hibernate.cfg.xml";

    private SessionFactory sessionFactory;

    @Override
    public void onEnable() {
        sessionFactory = new Configuration()
            .configure(new File(this.getDataFolder().getAbsolutePath()   "/"   HIBERNATE_CONFIG_FILE_NAME))
            .addAnnotatedClass(Session.class)
            .addAnnotatedClass(Action.class)
            .buildSessionFactory();

        ActionRepository actionRepository = new ActionRepository(sessionFactory);
        SessionRepository sessionRepository = new SessionRepository(sessionFactory);

        registerListener(this, actionRepository, sessionRepository);
    }

    @Override
    public void onDisable() {
        if (this.sessionFactory != null) {
            this.sessionFactory.close();
        }
    }

    private void registerListener(SessionUtil instance, ActionRepository actionRepository, SessionRepository sessionRepository) {
        this.getProxy().getPluginManager().registerListener(instance, new PlayerJoinListener(sessionRepository));
        this.getProxy().getPluginManager().registerListener(instance, new PlayerQuitListener(sessionRepository));
        this.getProxy().getPluginManager().registerListener(instance, new PlayerChatListener(sessionRepository, actionRepository));
    }
}

The issue that I am facing is that on startup, the following exception is thrown:

WARNING] Exception encountered when loading plugin: SessionUtil
java.lang.ExceptionInInitializerError
    at io.jakobi.sessionutil.SessionUtil.onEnable(SessionUtil.java:27)
    at net.md_5.bungee.api.plugin.PluginManager.enablePlugins(PluginManager.java:265)
    at net.md_5.bungee.BungeeCord.start(BungeeCord.java:285)
    at net.md_5.bungee.BungeeCordLauncher.main(BungeeCordLauncher.java:67)
    at net.md_5.bungee.Bootstrap.main(Bootstrap.java:15)
Caused by: java.lang.IllegalArgumentException: Invalid logger interface org.hibernate.internal.CoreMessageLogger (implementation not found in PluginClassloader(desc=PluginDescription(name=SessionUtil, main=io.jakobi.sessionutil.SessionUtil, version=1.0-SNAPSHOT, author=Lukas Jakobi <[email protected]>, depends=[], softDepends=[], file=plugins/sessionutil-1.0-SNAPSHOT.jar, description=A utility plugin to manage user sessions, libraries=[])))
    at org.jboss.logging.Logger$1.run(Logger.java:2556)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
    at org.jboss.logging.Logger.getMessageLogger(Logger.java:2529)
    at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
    at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:29)
    at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:25)
    at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:106)
    ... 5 more

A quick google search didn't really help. I found a comment saying I have to initialize the logger with Hibernate.initalize(object). I could not get that to work either.

Thanks in advance for any help! :)

CodePudding user response:

I don't know how class loading works in this "environment", but the hibernate-core.jar should contain a class called org.hibernate.internal.CoreMessageLogger_$logger, which is the logger implementation that apparently can't be found. Maybe the class loader is broken?

CodePudding user response:

Your maven shade plugin contains the following:

<configuration>
    <minimizeJar>true</minimizeJar>
</configuration>

This causes all the logging dependencies to be dropped while shading. Removing this line will fix the issue.

  • Related