2008-10-01 66 views
3

希望我能正確解釋這個問題。我有3個類來處理我的實體。JPA - 未知的實體bean類

@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) 

我正在運行netbeans 6.1版本的gla與它一起的ssfish。 MySql 5.0。

回答

1

根據錯誤信息和我從你的代碼中得出的結果,這個錯誤似乎在persistence.xml文件中,你能稍微詳細一點嗎?

+1

我找到了答案。 Netbeans /玻璃魚似乎需要一些工作。我不得不取消部署,停止服務器,然後重新啓動,然後工作正常。 – arinte 2008-10-03 14:31:44

5

定義在類標籤這個實體的persistence.xml

0

裏面我有同樣的錯誤,並補充上述信息,我的情況是一個ClassLoader的問題。我的應用程序有三個文件。一個依賴於app-lib.jar(包含pojo和數據庫實體的庫)和依賴於app-lib.jar的web-module.war的ejb-module.jar。

在部署中,app-lib.jar由glassfish加載兩次。谷歌搜索,我發現我應該將app-lib.jar複製到glassfish域中的「共享」庫。我已將postgresql.jar複製到「domain-dir/lib」,將我的app-lib.jar複製到「domain-dir/lib/applibs」。完成後,應用程序就像一個魅力。

的使用說明可以在這裏找到:http://docs.oracle.com/cd/E19798-01/821-1752/beade/index.html

0

我解決這個問題創造一個ContextListener在我的Web應用程序,調用實體管理器工廠在破壞環境的密切,:

public void contextDestroyed(ServletContextEvent servletContextEvent) { 
    try { 
     logger.info("contextDestroyed..."); 
     LifeCycleManager lifeCycleManager = ServiceLocator.getLifeCycleManager(); 
     lifeCycleManager.closeEntityManagerFactory(); 

    } catch (Exception e) { 
     logger.error(e.getMessage(), e); 
    } 
} 

我也有名字LifeCycleManager創建一個bean和它們內部調用DAO方法關閉實體管理器工廠:

public void closeEntityManagerFactory() throws BusinessException { 
     logger.info("closeEntityManager"); 
     try { 
      logger.info("closing entity manager factory..."); 
      genericDAO.closeEntityManagerFactory(); 
      logger.info("Entity manager factiry closed"); 
     } catch (Exception e) { 
      throw new BusinessException(BusinessErrorCode.CODIGO_EJEMPLO_01, Severity.ERROR); 
     } 
    } 

Insid E中的DAO:

...

@Autowired 
private EntityManagerFactory entityManagerFactory; 

...

public void closeEntityManagerFactory() { 
     logger.info("closing entity manager factory"); 
     getEntityManagerFactory().close(); 
     logger.info("entity manager factory closed"); 
    } 

使用這個我部署從我的Eclipse環境的破壞上下文中調用了一個變化,每次。 我希望可以幫助你們,我的環境是WebLogic Server 11gR1和JPA 1.0。