Google App Engine ClassNotPersistenceCapableException

走远了吗. 提交于 2019-12-02 15:03:45

问题


I have the following class :

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.*;

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class PayPal_Message
{
  @PrimaryKey
  @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
  private Long id;
  @Persistent
  private Text content;
  @Persistent
  private String time;

  public PayPal_Message(Text content,String time)
  {
    this.content=content;
    this.time=time;
  }

  public Long getId() { return id; }
  public Text getContent() { return content; }
  public String getTime() { return time; }
  public void setContent(Text content) { this.content=content; }
  public void setTime(String time) { this.time=time; }
}

It used to be in a package, and works fine, now I put all classes in the default package, which caused me this error :

org.datanucleus.jdo.exceptions.ClassNotPersistenceCapableException: The class "The class "PayPal_Message" 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." 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 for the class is not found. NestedThrowables: org.datanucleus.exceptions.ClassNotPersistableException: The class "PayPal_Message" 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.

What should I do to fix it ?


回答1:


Explanation: classes in the default package are not visible/importable by classes inside a package.

Try the following examples:

public class Entity {}

(thus without package!) and

package persistence;

public class EntityManager {
    public static void main(String... args) {
        Entity entity = new Entity();
    }
}

Does it work? No? How would you ever import it? That's the problem which happens behind the scenes!




回答2:


I've gotten these exceptions sometimes for no discernible reason.

Adding a space somewhere in the persistent class and rebuilding has fixed it for me in the past. No idea why it happens or why rebuilding fixes it, but worth a shot at least.




回答3:


I ended up putting them back to the package, and it works fine now.



来源:https://stackoverflow.com/questions/2701565/google-app-engine-classnotpersistencecapableexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!