Using Hibernate ORM in a Spigot plugin

Discussion in 'Spigot Plugin Development' started by ItsSteve, Jun 25, 2016.

Thread Status:
Not open for further replies.
  1. Note: Please read the entire post to see WHY I am trying to use Hibernate!

    Hi,

    I'm having a bit of a strange problem with a private plugin I'm writing. I am trying to use the Hibernate ORM to handle the database part of the plugin (which is a big part of it)

    The main part of error I'm getting is:
    Code (Text):
    [20:57:42 WARN]: javax.persistence.PersistenceException: No Persistence provider for EntityManager named PersistenceUnitNameHere
    [20:57:42 WARN]:     at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
    [20:57:42 WARN]:     at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
    My persistence.xml file:
    Code (Text):
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0"
                 xmlns="http://java.sun.com/xml/ns/persistence"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
        <persistence-unit name="PersistenceUnitNameHere" transaction-type="RESOURCE_LOCAL">
            <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
            <validation-mode>NONE</validation-mode>
            <properties>
                <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
                <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/clans"/>
                <property name="javax.persistence.jdbc.password" value=""/>
                <property name="javax.persistence.jdbc.user" value="root"/>
            </properties>
        </persistence-unit>
    </persistence>
    The code to instantiate the EntityManagerFactory:
    Code (Java):
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersistenceUnitNameHere");
    I have my persistence.xml file in the classpath, under META-INF/persistence.xml, where it needs to be.
    It seems like a few other people have had this problem, particularly with Bukkit plugins, but I can not find a solution.

    What I've tried so far:
    - Putting the file in
    Code (Text):
    src/main/resources/META-INF/persistence.xml
    - Overriding the classloader for the plugin (or at least, trying to) to force it to use the real path when it requests the file; doesn't seem to do anything, even though I put in a logging statement.
    - Using many different configurations and tutorials; NOTHING WORKS.

    What's weird is that it works perfectly fine standalone.
    Also, before anyone says it, I don't want to use YML files out of fear that they will grow too big with the different data structures the plugin will have.

    One last thing: The code to create an EntityManagerFactory is being executed in onEnable(). Could it be that Bukkit isn't loading the files properly?

    Thanks,
    ItsSteve
     
    • Like Like x 1
Thread Status:
Not open for further replies.