导致java.lang.NoClassDefFoundError的EJB抽象实体?

时间:2011-09-14 03:37:54

标签: java java-ee jpa eclipselink

在我的ejb项目中,我定义了一个名为DataObjectEntity.java的抽象实体类,并让所有实体扩展此类。其目的是可以重用公共字段,并且可以更容易地记录系统中的活动。

@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的一些更改。错误仍然存​​在。我甚至检查了一个新的工作副本,以对支持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的实体java文件重命名为.class。等待glassfish编译并报告错误。然后将其更改回.java。等待glassfish再次编译然后清理并构建,部署。每次都有效。

1 个答案:

答案 0 :(得分:1)

异常说类实体/ DataObjectEntity_不是DataObjectEntity,注意“_”。

这是一个JPA2元模型类,仅用于Criteria API的类型安全版本。它不是必需的,也不应该引起任何问题。您的应用程序是否仍然成功运行?

这些模型类是可选的,通常不需要,因此错过它们不应该导致任何问题。它们仅在编译时生成,可以是您的IDE,也可以是EclipseLinkk元模型生成器,它必须连接到您的构建过程。

您更改以解决问题毫无意义,似乎您可能刚刚遇到IDE的编译问题。