2011-09-14 56 views
2

在我的ejb項目中,我定義了一個名爲DataObjectEntity.java的抽象實體類,並讓所有實體擴展這個類。其目的是使通用字段可以重複使用,並且系統中的活動記錄可以更容易。導致java.lang.NoClassDefFoundError的EJB抽象實體?

@Entity 
@Inheritance(strategy= InheritanceType.TABLE_PER_CLASS) 
public abstract class DataObjectEntity implements Serializable { 
    private static final long serialVersionUID = 1L; 
    @Transient 
    protected Logger log = Logger.getLogger(getClass()); 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id; 
    private PersonEntity createdBy; 
    @Temporal(javax.persistence.TemporalType.DATE) 
    private Date createdAt; 
    private PersonEntity lastModifiedBy; 
    @Temporal(javax.persistence.TemporalType.DATE) 
    private Date lastModifiedAt; 
    private boolean archived; 

    public DataObjectEntity() { 
    createdAt = new Date(); 
    lastModifiedAt = new Date(); 
    archived = false; 
    } 

    public DataObjectEntity(PersonEntity createdBy) { 
    this(); 
    this.createdBy = createdBy; 
    this.lastModifiedBy = createdBy;  
    } 

    public void modified(PersonEntity modifiedBy){ 
    this.lastModifiedBy = modifiedBy; 
    this.lastModifiedAt = new Date(); 
    log.info("Object " + id + " modified by " + modifiedBy.getName()); 
    } 

    public void created(PersonEntity createdBy){ 
    this.createdBy = createdBy; 
    this.lastModifiedBy = createdBy; 
    log.info("Object " + id + " created by " + createdBy.getName()); 
    } 

    //getters and setters 
} 

然後我用NetBeans的內置功能來生成實體類JSF頁面。一切都很好。我可以很好地運行該項目。

但是在添加一個新的實體後,我在嘗試部署時得到了這個超類實體的NoClassDefFoundError。新實體非常簡單,具有用預先存在的實體類之一定義的1-1關係。我嘗試了所有我能想到的:清潔&構建,重新啓動glassfish,刪除所有表,爲新實體類生成JSF,儘管我不需要它......但是沒有任何工作。

最終我刪除了我的新實體,只留下了現有備份bean的一些更改。錯誤仍然存​​在。我甚至檢出了一份新的工作副本,將相同的更改應用於後備豆 - 事實證明,副本部署良好。我的一個隊友在嘗試添加新實體時遇到了完全相同的錯誤。任何想法可能是什麼原因?

WARNING: entity/DataObjectEntity_ 
java.lang.NoClassDefFoundError: entity/DataObjectEntity_ 
at java.lang.ClassLoader.defineClass1(Native Method) 
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) 
at java.lang.ClassLoader.defineClass(ClassLoader.java:615) 
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) 
at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:927) 
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1486) 
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1369) 
at java.lang.Class.forName0(Native Method) 
at java.lang.Class.forName(Class.java:247) 
at org.eclipse.persistence.internal.helper.ConversionManager.convertObjectToClass(ConversionManager.java:438) 
at org.eclipse.persistence.internal.helper.ConversionManager.convertObject(ConversionManager.java:141) 
at org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.convertObject(DatasourcePlatform.java:160) 
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.initializeCanonicalMetamodel(EntityManagerSetupImpl.java:2552) 
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.getMetamodel(EntityManagerSetupImpl.java:2531) 
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:484) 
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188) 
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277) 
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:290) 
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:268) 
at org.glassfish.persistence.jpa.PersistenceUnitLoader.doJava2DB(PersistenceUnitLoader.java:373) 
at org.glassfish.persistence.jpa.JPADeployer$2.visitPUD(JPADeployer.java:435) 
at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:483) 
at org.glassfish.persistence.jpa.JPADeployer.iterateInitializedPUsAtApplicationPrepare(JPADeployer.java:465) 
at org.glassfish.persistence.jpa.JPADeployer.event(JPADeployer.java:386) 
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128) 
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:453) 
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240) 
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:382) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1244) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1232) 
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:459) 
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:209) 
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168) 
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117) 
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:238) 
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) 
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725) 
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019) 
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225) 
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) 
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) 
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) 
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) 
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) 
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) 
at com.sun.grizzly.ContextTask.run(ContextTask.java:71) 
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) 
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) 
at java.lang.Thread.run(Thread.java:680) 
Caused by: java.lang.ClassNotFoundException: entity.DataObjectEntity_ 
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1519) 
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1369) 
... 53 more 

persistence.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.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_2_0.xsd"> 
    <persistence-unit name="MyProject-warPU" transaction-type="JTA"> 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
    <jta-data-source>jdbc/myprojectdb</jta-data-source> 
    <exclude-unlisted-classes>false</exclude-unlisted-classes> 
    <properties> 
     <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> 
    </properties> 
    </persistence-unit> 
</persistence> 

更新:我的隊友發現了一個很奇怪的,但有希望的方式來解決這個問題:重命名報告的NoClassDefFoundError到的.class實體的java文件。等待glassfish編譯並報告錯誤。然後將其更改回.java。等待glassfish再次編譯,然後清理並構建,部署。每次工作。

+0

你有任何集成測試嗎?如果是,他們通過。粘貼你的persistence.xml。我會建議創建一個測試應用程序與這個類,如果你有錯誤粘貼從測試應用程序在這裏完整的代碼。真的很難說從你發佈的內容。 – Shahzeb

+0

我神祕地「解決」了這個問題,增加了'createdBy = null; lastModifiedBy = null;'在DataObjectEntity類的默認構造函數中。爲什麼?! – Wei

+0

可能與JPA2元模型類(使用「_」後綴的類)有關,並且它們需要生成。畢竟這是消息中提到的內容。爲什麼你選擇的JPA實現有一個問題,該類不存在是另一回事...... – DataNucleus

回答

1

例外說實體/ DataObjectEntity_不是DataObjectEntity,請注意「_」。

這是一個JPA2元模型類,僅用於Criteria API的類型安全版本。這不是必需的,也不應該引起任何問題。你的應用程序仍然運行成功嗎?

這些模型類是可選的,通常不需要,所以錯過它們不應該引起任何問題。它們僅在編譯時生成,無論是由IDE還是由必須連接到構建過程的EclipseLinkk元模型生成器生成。

您改變以解決問題沒有任何意義,好像您可能剛剛對IDE有一些編譯問題。

+0

我正在使用netbeans。我從未見過同樣的問題,但我的其他隊友都有。但在其他一些類中,像PersonEntity是DataObjectEntity的子類,也是CustomerEntity和SystemUserEntity的超類...並且據他說,除了反覆清理,構建,部署和重新啓動Netbeans以最終使問題消失之外,他什麼都沒做。 ... – Wei