为什么我在托管模式下运行 GWT App Engine 应用程序时会收到 ClassNotPersistableException?
当我尝试对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;
}