为什么在托管模式下运行 GWT App Engine 应用程序时会出现 ClassNotPersistableException?

2024-03-28

当我尝试对 GWT/App Engine 应用程序的本地 JDO 数据存储执行查询时,我随机收到 org.datanucleus.exceptions.ClassNotPersistableException。仅当我在托管模式下运行应用程序时才会发生这种情况。当我将其部署到 Google App Engine 时,一切都运行良好。

堆栈跟踪:

org.datanucleus.exceptions.ClassNotPersistableException: The class "com.wayd.server.beans.WinePost" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
    at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:305)
    at org.datanucleus.ObjectManagerImpl.getExtent(ObjectManagerImpl.java:3700)
    at org.datanucleus.jdo.JDOPersistenceManager.getExtent(JDOPersistenceManager.java:1515)
    at com.wayd.server.WinePostServiceImpl.getPosts(WinePostServiceImpl.java:212)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:527)
    ... 25 more
Caused by: org.datanucleus.exceptions.ClassNotPersistableException: The class "com.wayd.server.beans.WinePost" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
    at org.datanucleus.ObjectManagerImpl.assertClassPersistable(ObjectManagerImpl.java:3830)
    at org.datanucleus.ObjectManagerImpl.getExtent(ObjectManagerImpl.java:3693)
    ... 32 more)

WinePost 类是一个非常简单的 JDO 持久性类:

@PersistenceCapable(identityType = IdentityType.APPLICATION) 公共类 WinePost {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;

@Persistent
private User author;

@Persistent
private String grape;

@Persistent
private String comment;

public WinePost(final User author, final String grape,
        final String comment) {
    super();
    this.grape = grape;
    this.comment = comment;
}

public User getAuthor() {
    return author;
}

public void setAuthor(final User author) {
    this.author = author;
}

public Long getId() {
    return id;
}

public void setId(final Long id) {
    this.id = id;
}

public String getGrape() {
    return grape;
}

public void setGrape(final String grape) {
    this.grape = grape;
}

public String getComment() {
    return comment;
}

public void setComment(final String comment) {
    this.comment = comment;
}

public String getUserNickname() {
    String retVal = null;
    if (author != null) {
        retVal = author.getNickname();
    }
    return retVal;
}

public WinePostModel getWinePostModel() {
    final WinePostModel winePostModel = new WinePostModel(grape, vintage, getUserNickName());
    return winePostModel;
}

}

数据存储查询通过以下方法执行:

public ArrayList<WinePostModel> getPosts() {
        final ArrayList<WinePostModel> posts = new ArrayList<WinePostModel>();
        final PersistenceManager persistenceManager = PMF.get()
        .getPersistenceManager();

        final Extent<WinePost> winePostExtent = persistenceManager.getExtent(
                WinePost.class, false);
        for (final WinePost winePost : winePostExtent) {
            posts.add(winePost.getWinePostModel());
        }
        winePostExtent.closeAll();

        return posts;
    }

我很确定你的代码没有任何问题。出现此错误的原因是 Datanucleus 增强器出现问题。

如果您看到此错误,请退出 Jetty 并检查 Eclipse 内的控制台(您需要在控制台窗口上方的小工具栏中选择正确的控制台)。它应该这样说:

DataNucleusEnhancer(版本1.1.4):类的增强 DataNucleus Enhancer 已成功完成X类。计时:输入 = 547 毫秒,增强 = 76 毫秒,总计 = 623 毫秒。请查阅日志以获取完整详细信息

... 在哪里X是它已处理的类数。该数量应等于您定义的“实体”类别的数量。

但有时,由于某种原因它会显示 0,这就是您收到 ClassNotPersistableException 错误的原因。

要修复此问题,请打开一个实体类并更改某些内容(添加空格或其他内容)并保存。检查控制台,直到它显示它已增强了您的所有实体类。然后重新启动调试器并重试。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么在托管模式下运行 GWT App Engine 应用程序时会出现 ClassNotPersistableException? 的相关文章

随机推荐