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

2022-09-04 08:24:24

当我尝试对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) public class 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;
    }

答案 1

我很确定你的代码没有错。您收到此错误的原因是由于Datanucleus增强器的问题。

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

DataNucleus Enhancer(版本1.1.4):DataNucleus Enhancer的类增强在X类中成功完成。定时:输入=547毫秒,增强=76毫秒,总计=623毫秒。有关完整详细信息,请参阅日志

...其中 X 是它已处理的类数。该数字应等于已定义的“实体”分类的数量。

但有时,由于某种原因,它会说0,这就是为什么你得到ClassNotPersistableException错误。

若要修复,请打开实体类并更改某些内容(添加空格或某些内容)并保存。检查控制台,直到它说它已增强所有实体类。然后重新启动调试器并重试。


答案 2

发布以供将来遇到相同问题的任何人参考,尽管这是一个旧线程。

我遇到了“相同”的问题,发现我的类路径有多个datanucleus-appengine-1.0.7.final.jar实例。我从日志中了解到这一点,当我尝试构建工作区时,日志会提示这一点。下面是日志内容。

java.lang.RuntimeException:在 com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:59) at com.google.appengine.tools.enhancer.Enhancer.(Enhance.java:60) at com.google.appengine.tools.enhancer.Enhance.main(Enhance.java:41) Caused by: java.lang.reflect.InvocationTargetException 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:597) atcom.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:57) ...2 更多原因:org.datanucleus.exceptions.NucleusException:Plugin (Bundle) “org.datanucleus.store.appengine”已经注册。确保类路径中没有同一插件的多个 JAR 版本。URL“file:/G:/eclipse/plugins/com.google.appengine.eclipse.sdkbundle.1.3.4_1.3.4.v201005212032/appengine-java-sdk-1.3.4/lib/user/orm/datanucleus-appengine-1.0.7.final.jar”已注册,您正在尝试注册位于 URL “file:/G:/WS_Quotemandu/quotemandu/war/WEB-INF/lib/datanucleus-appengine-1.0.7.final.jar..java.plugin”org.datanucleus.plugin.NonManagedPluginRegistry.registerBundle(NonManagedPluginRegistry.java:340) at org.datanucleus.plugin.NonManagedPluginRegistry.registerExtensions(NonManagedPluginRegistry.java:222) at org.datanucleus.plugin.NonManagedPluginRegistry.registerExtensionPoints(NonManagedPluginRegistry.java:153) at org.datanucleus.plugin.PluginManager.registerExtensionPoints(PluginManager.java:82) at org.datanucleus.OMFContext.(OMFContext.java:160) at org.datanucleus.enhancer.DataNucleusEnhancer.(DataNucleusEnhancer.java:172)在 org.datanucleus.enhancer.DataNucleusEnhancer。(DataNucleusEnhancer.java:150) at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1157) ...7更多

G:/eclipse/plugins/com.google.appengine.eclipse.sdkbundle.1.3.4_1.3.4.v201005212032/appengine-java-sdk-1.3.4/lib/user/orm/datanucleus-appengine-1.0.7.final.jar

file:/G:/WS_Quotemandu/quotemandu/war/WEB-INF/lib/datanucleus-appengine-1.0.7.final.jar

希望这有帮助!


推荐