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!


    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(
    [20:57:42 WARN]:     at javax.persistence.Persistence.createEntityManagerFactory(
    My persistence.xml file:
    Code (Text):
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0"
        <persistence-unit name="PersistenceUnitNameHere" transaction-type="RESOURCE_LOCAL">
                <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"/>
    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):
    - 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?

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