netbeans中的例外JPA

时间:2017-11-16 14:43:53

标签: jpa netbeans

在netbeans 8.1和mysql中使用java持久性API。 我已经从数据库自动创建了实体类,并为每个实体创建了自动JPA控制器。 现在的主要方法是:

    public static void main(String[] args) {
/*   
 */   EntityManagerFactory emf = Persistence.createEntityManagerFactory("TravelPU");
    Person p1 = new Person(1);
    p1.setName("Antonio");
    p1.setJobtitle("programmer");
    Person p2 = new Person(2);
    p2.setName("John");
    p2.setJobtitle("sysadmin");

    PersonJpaController jpap =  new PersonJpaController(emf);
    try {
        jpap.create(p1);
        jpap.create(p2);
        System.out.println(jpap.findPerson(1));
    } catch (Exception ex) {
        Logger.getLogger(Travel.class.getName()).log(Level.SEVERE, null, ex);
    }
    finally {
        emf.close();
    }
}

当我跑步时,我得到以下异常: 我不知道是什么问题,库是EclipseLink(JPA 2.1)。 操作系统是debian 9。 我无话可说,我给了你有用的信息,我认为是必要的。

   Exception in thread "main" Local Exception Stack: 
    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$AppClassLoader@24d46ca6
    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 [TravelPU] 
    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:79)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
        at travel.Travel.main(Travel.java:30)
    Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
    Exception Description: Predeployment of PersistenceUnit [TravelPU] failed.
    Internal Exception: java.lang.IncompatibleClassChangeError: Implementing class
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1954)
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1945)
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:96)
        ... 4 more
    Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
    Exception Description: Predeployment of PersistenceUnit [TravelPU] failed.
    Internal Exception: java.lang.IncompatibleClassChangeError: Implementing class
        at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:230)
        ... 8 more
    Caused by: java.lang.IncompatibleClassChangeError: Implementing class
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processEntityMappings(MetadataProcessor.java:538)
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:581)
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1869)
        ... 6 more
    /home/XXX/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 1
    BUILD FAILED (total time: 0 seconds)

的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="TravelPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>model.Carrental</class>
    <class>model.Hotel</class>
    <class>model.Flight</class>
    <class>model.Person</class>
    <class>model.Persontrip</class>
    <class>model.Triptype</class>
    <class>model.Trip</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/travel?zeroDateTimeBehavior=convertToNull"/>
      <property name="javax.persistence.jdbc.user" value="xxxxxx"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.password" value="xxxxxx"/>
    </properties>
  </persistence-unit>
</persistence>

0 个答案:

没有答案