gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:51:29 27 4
gpt4 key购买 nike

在我的 ejb 项目中,我定义了一个名为 DataObjectEntity.java 的抽象实体类,并让所有实体都扩展了这个类。目的是可以重复使用公共(public)字段,并且可以更轻松地记录系统中的 Activity 。

@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 页面。一切都很好。我可以很好地运行该项目。

但是在添加一个新实体之后,我在尝试部署时得到了父类(super class)实体的这个 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 再次编译,然后清理并构建、部署。每次都有效。

最佳答案

异常表示类实体/DataObjectEntity_ 而不是 DataObjectEntity,请注意“_”。

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

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

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

关于java - EJB 抽象实体导致 java.lang.NoClassDefFoundError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7410987/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com