我的以下代码正在我的Windows上运行,但不适用于我的Linux Mint。添加了所有相关的库。 我得到了createEntityManagerFactory行的这个异常:
javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "JPA_probaPU" after trying the following discovered implementations: org.eclipse.persistence.jpa.PersistenceProvider from provider: org.eclipse.persistence.jpa.PersistenceProvider
我的java文件:
package jpa_proba;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.eclipse.persistence.exceptions.EntityManagerSetupException;
public class JPA_proba {
public static void main(String[] args) {
try{
EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPA_probaPU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
//Integer id, String isbn, String szerzo, String cim, String mufaj, int ar, int elerheto
Konyv k = new Konyv(null, "654654444444", "Kiss Béla", "Hogyan ne csináljunk semmit?", "dráma", 500, 1);
em.persist(k);
em.getTransaction().commit();
}
catch(Exception ex){
System.out.println(ex);
}
}
}
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="JPA_probaPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>jpa_proba.Konyv</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/helix1?zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.password" value="123456"/>
</properties>
</persistence-unit>
</persistence>
错误:
Exception in thread "main" javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "JPA_probaPU" after trying the following discovered implementations: org.eclipse.persistence.jpa.PersistenceProvider from provider: org.eclipse.persistence.jpa.PersistenceProvider
at javax.persistence.Persistence.createPersistenceException(Persistence.java:244)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:186)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
at jpa_proba.JPA_proba.main(JPA_proba.java:13)
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoad er@5caf905d
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [JPA_probaPU] failed.
Internal Exception: java.lang.IncompatibleClassChangeError: Implementing class
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152)
答案 0 :(得分:0)
您将获得Internal Exception: java.lang.IncompatibleClassChangeError: Implementing class
。
如果您有多个相同类/ jar的版本,可能会发生这种情况。