Intellij Plugin clashes with JPA Hibernate
Hello,
I build a little plugin for Intellij that also utilizes JPA with the Hibernate distribution. Unfortunaly the plugin isn't able to connect to a database.
Every time i run the code of my DBConnector class:
EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("default");
the plugin chrashes with the Exception:
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at repositories.DBConnector.getConnection(DBConnector.java:10)
at repositories.EntityRepositoryImpl.<init>(EntityRepositoryImpl.java:26)
at repositories.EntityRepositoryImpl.<clinit>(EntityRepositoryImpl.java:13)
... 54 more
I debugged a little bit into it and it appears that the com.intellij.util.lang.PathClassLoader can't load the HibernatePersistenceProvider.
The persistence.xml is within the main/resources/META-INF folder and works fine when deployed in another application than an Intellij Plugin.
Also in Project settings in Facets the correct path is set.
All Hibernate and JPA dependencies are set in the build.gradle
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
compileOnly('javax.ejb:javax.ejb-api:3.2.2')
implementation('org.hibernate:hibernate-core:5.6.1.Final')
implementation 'mysql:mysql-connector-java:8.0.29'
}
Any Known Solutions to this problem?
请先登录再写评论。
Ok so I fixed the problem thanks to:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206782735-How-to-use-JPA-Hibernate-in-Plugin-?page=1#community_comment_206172985
and
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006504019-loader-constraint-violation
See also https://plugins.jetbrains.com/docs/intellij/plugin-class-loaders.html#using-serviceloader