NetBeans11.2 - JPA - java.lang.IllegalArgumentException:对象:javaapplication4.Id[id=5] 不是已知实体类型

NetBeans11.2 - JPA - java.lang.IllegalArgumentException: Object: javaapplication4.Id[ id=5 ] is not a known entity type

尝试在 MacOS 上的 NetBeans 11.2 中使用 JPA 时,我反复遇到以下异常。

java.lang.IllegalArgumentException: Object: javaapplication4.Id[ id=5 ] is not a known entity type.

at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4228)

at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:496)

at javaapplication4.JavaApplication4.main(JavaApplication4.java:30)

我的主要class:

package javaapplication4;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author Informatica
 */
public class JavaApplication4 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JavaApplication4PU");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        try{
            Id id = new Id();
            em.persist(id);
            tx.commit();

        }catch(Exception e ){
            e.printStackTrace();
            tx.rollback();
        }


        em.close();
        emf.close();
    }

}

我的实体Class:

package javaapplication4;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Informatica
 */
@Entity
@Table(name = "ID")
@NamedQueries({
    @NamedQuery(name = "Id.findAll", query = "SELECT i FROM Id i"),
    @NamedQuery(name = "Id.findById", query = "SELECT i FROM Id i WHERE i.id = :id")})
public class Id implements Serializable {

    private static final long serialVersionUID = 1L;
    @javax.persistence.Id
    @Column(name = "ID")
    private Long id;

    public Id() {
        this.id = new Long(5);
    }

    public Id(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Id)) {
            return false;
        }
        Id other = (Id) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "javaapplication4.Id[ id=" + id + " ]";
    }

}

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="JavaApplication4PU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>javaapplication4.Id</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/s"/>
      <property name="javax.persistence.jdbc.user" value="s"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.password" value="s"/>
      <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
    </properties>
  </persistence-unit>
</persistence>

我的图书馆:

libraries

classpath

我正在使用 Derby DB。

如果您能找到问题所在,请告诉我。提前谢谢你。

问题已解决,由于某些原因它只适用于 jdk 8,切换 jkd 解决了问题