为什么在托管模式下运行GWT App Engine应用程序时会出现ClassNotPersistableException? [英] Why do I get ClassNotPersistableException while running GWT App Engine application in hosted mode?

查看:165
本文介绍了为什么在托管模式下运行GWT App Engine应用程序时会出现ClassNotPersistableException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在我的GWT / App Engine应用程序的本地JDO数据存储上执行查询时,我随机得到一个org.datanucleus.exceptions.ClassNotPersistableException。只有当我在托管模式下运行应用程序时才会发生这种情况。当我将它部署到Google App Engine时,一切都很完美。

堆栈跟踪:

  org.datanucleus.exceptions.ClassNotPersistableException:类com.wayd.server.beans.WinePost不可持久化。这意味着它或者没有被增强,或者文件的增强版本不在CLASSPATH中(或者被未增强的版本隐藏),或者没有找到该类的元数据/注释。 
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
由于: org.datanucleus.exceptions.ClassNotPersistableException:类com.wayd.server.beans.WinePost不可持久化。这意味着它或者没有被增强,或者文件的增强版本不在CLASSPATH中(或者被未增强的版本隐藏),或者没有找到该类的元数据/注释。
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长ID;

@Persistent
私人用户作者;

@Persistent
私人字符串葡萄;

@Persistent
私人字符串评论;

public WinePost(最终用户作者,最终字符串葡萄,
最终字符串评论){
super();
this.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());
返回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);
(最终WinePost winePost:winePostExtent){
posts.add(winePost.getWinePostModel());
}
winePostExtent.closeAll();

返回帖子;
}


解决方案

你的代码不对。你得到这个错误的原因是由于Datanucleus增强器的问题。如果你看到这个错误,退出Jetty并检查Eclipse内部的控制台(你需要在控制台窗口上方的小工具栏中选择正确的控制台)。它应该是这样的:

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



...其中 X 是它处理的类的数量。该数字应该等于您定义的实体类别的数量。



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



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


I am randomly getting an org.datanucleus.exceptions.ClassNotPersistableException when I try to perform a query on the local JDO data store of my GWT/App Engine application. This only happens when I run the application on Hosted mode. When I deploy it to the Google App Engine everything works perfectly.

Stack Trace:

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 class is a very simple JDO persistence capable class:

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

}

The datastore query is performed by the following method:

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

解决方案

I am pretty sure there's nothing wrong with your code. The reason you get this error is because of a problem with the Datanucleus enhancer.

If you see this error, quit Jetty and check the console inside Eclipse (you'll need to select the correct console in the little toolbar above the console window). It should say something like:

DataNucleus Enhancer (version 1.1.4) : Enhancement of classes DataNucleus Enhancer completed with success for X classes. Timings : input=547 ms, enhance=76 ms, total=623 ms. Consult the log for full details

... where X is the number of classes it has processed. The number should be equal to the number of 'entity' classed you have defined.

But sometimes, for some reason it will say 0 which is why you get the ClassNotPersistableException error.

To fix, open an entity class and change something (add a space or something) and save. Check the console until it says that it has enhanced all of your entity classes. Then restart the debugger and try again.

这篇关于为什么在托管模式下运行GWT App Engine应用程序时会出现ClassNotPersistableException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆