How to use JPA / Hibernate in Plugin?


I am writing a Plugin that gets some data out of a database in order to show it as code documentation.

The Problem is that I cannot create an EntityManagerFactory:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named myDatabase
     at javax.persistence.Persistence.createEntityManagerFactory(
     at javax.persistence.Persistence.createEntityManagerFactory(
     at org.myorganization.DatabaseModelDocumentationProvider.initializeDocumentation(

When running the code in unit tests there is no problem. The exception only appears when running the plugin in the target platform.

I have tried to locate the persistence.xml in both /META-INF and /src/META-INF but neither works.

Thanks for help!

1 comment
Comment actions Permalink

Hi again,

I managed to solve the problem by setting the contextClassLoader to the ClassLoader of the invoking class. I did this because the contextClassLoader does not know the classes from the libraries.

So the code looks just something like this:

ClassLoader old = Thread.currentThread().getContextClassLoader();

/* JPA/Hibernate code ... */




Please sign in to leave a comment.