开发者

EJB abstract entity causing java.lang.NoClassDefFoundError?

In my ejb project I defined an abstract entity class called DataObjectEntity.java, and have all entities extend this class. The purpose is such that common fields can be reused and logging of activities in the system can be easier.

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

Then I used netbeans' built-in feature to generate JSF pages from entity classes. Everything was fine. I could run the project just fine.

But after adding a new entity, I got this NoClassDefFoundError for the super class entity when trying to deploy. The new entity was really simple with a 1-1 relationship defined with one of the pre-existing entity class. I tried everything I could think of: clean&build, restarting glassfish, dropping all tables, generating JSF for the new entity class though I don't need it... But nothing worked.

Eventually I deleted my new entity and only left some changes on the existing backing beans. And the error still persists. I even checked out a fresh working copy to apply the same changes to the backing beans - turned out that copy deploys fine. One of my teammates is getting exactly the same error when he tries to add a new entity. Any idea what might be the cause?

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.j开发者_如何学Cava: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

The persistence.xml file:

<?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>

Update: My teammate found a very strange but promising way to fix this: rename the entity java file that reports the NoClassDefFoundError to .class. Wait for glassfish to compile and report errors. Then change it back to .java. Wait for glassfish to compile again then clean and build, deploy. Works every time.


The exception say the class entity/DataObjectEntity_ not DataObjectEntity, note the "_".

This is a JPA2 metamodel class that is only used for the type safe version of the Criteria API. It is not required, and should not cause any issues. Does you application still run successfully?

These model classes are optional and normally not needed, so missing them should not be causing any issue. They are generated only at compile time, either by your IDE, or by the EclipseLinkk meta-model generator that has to be hooked up to your build process.

You change to resolve the issue make no sense, seems like you may have just had some compile issue with your IDE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜