JPA-未知实体Bean类

时间:2020-03-06 14:59:43  来源:igfitidea点击:

希望我能正确解释这个问题。我有3个课程与我的实体打交道。

@MappedSuperclass
public abstract class Swab implements ISwab {
...
    private Collection<SwabAccounts> accounts;
...
}

@Entity
@Table(name="switches")
@DiscriminatorColumn(name="type")
@DiscriminatorValue(value="DMS500")
public class DmsSwab extends Swab implements ISwab, Serializable {
...
    private ObjectPool pool;
...
    @Transient 
    public ObjectPool getPool(){
        return pool;
    }
...
}

@Entity(name="swab_accounts")
public class SwabAccounts implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int swab_account_id;
    private int swab_id;
...
}

而在EJB中,查询就是以此方式进行的

DmsSwab dms = em.find(DmsSwab.class, 2);
    List<Swab> s = new ArrayList<Swab>(1);
    s.add(dms);

我的persistence.xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="dflow-pu" transaction-type="RESOURCE_LOCAL">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <class>com.dcom.sap.dms.DmsSwab</class>
    <class>com.dcom.sap.jpa.SwabAccounts</class>
    <properties>
      <property name="toplink.jdbc.user" value="dflow"/>
      <property name="toplink.jdbc.password" value="dflow"/>
      <property name="toplink.jdbc.url" value="jdbc:mysql://itcd-400447:3306/dflow"/>
      <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    </properties>
  </persistence-unit>
</persistence>

我收到此错误:

java.lang.IllegalArgumentException: Unknown entity bean class: class com.dcom.sap.dms.DmsSwab, please verify that this class has been marked with the @Entity annotation.
com.dcom.sap.SwabException: java.lang.IllegalArgumentException: Unknown entity bean class: class com.dcom.sap.dms.DmsSwab, please verify that this class has been marked with the @Entity annotation.
Caused by: java.lang.IllegalArgumentException: Unknown entity bean class: class com.dcom.sap.dms.DmsSwab, please verify that this class has been marked with the @Entity annotation.
        at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:306)
        at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.find(EntityManagerImpl.java:148)

我正在运行带有随附的glassfish版本的netbeans 6.1. MySQL 5.0。

解决方案

根据错误消息以及我从代码中得出的信息,该错误似乎在persistence.xml文件中,我们能否再详细一点?

在persistence.xml中的类标记中定义此实体