使用 PersistenceManager 删除对象时出现问题

发布于 2024-09-15 06:18:24 字数 2614 浏览 4 评论 0 原文

我创建了数据类并使用 PersistenceManager 存储数据,但后来我编辑了我的数据类,现在我在共享数据时遇到问题 我正在尝试删除此对象(pm.deletePersistent(e)),但我有例外:

javax.jdo.JDOUserException:无法删除一个或多个实例 NestedThrowables:org.datanucleus.jdo.exceptions.ClassNotPersistenceCapableException:类“类”java.lang.Class”不可持久。这意味着它要么尚未增强,或者文件的增强版本不在 CLASSPATH 中(或被未增强版本隐藏),或者找不到该类的元数据/注释。”不持久

那是我的数据类:

import com.google.appengine.api.datastore.Key;
import java.util.ArrayList;
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable

public class Task {
        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key key;

    @Persistent
    private String author;

    @Persistent
    private String task;

    @Persistent
    private Date date;

    @Persistent
    private String note;

    @Persistent
    private ArrayList<String> label; 

    @Persistent
    private int numberoflist;





    public Task (String author, String task,String note, Date date, int numberoflist)
    {
        this.author=author;
        this.task=task;
        this.date=date;
        this.numberoflist=numberoflist;
        this.note=note;
    }

那是我的 .jsp 文件,但 deletePersistentAll(Task.class) 或 pm.deletePersistent(e) 不起作用,因为类 Task 已更改(一个字段的类型从 User 更改为 String)

 try{                   
        PersistenceManager pm = PMF.get().getPersistenceManager();  
        pm.flush();
        Query query = pm.newQuery(Task.class);
        query.declareParameters("String authorParam");
        List<Task> results = (List<Task>) query.execute("user@mail");
            try
            {
                 if (results.iterator().hasNext())
                 {
                    for (Task e : results) 
                    {
                      pm.deletePersistent(e);
                      %>
                      <p><%= e.getTask() %> </p>
                      <%
                    }
                 }else 
                     {
                       %> 
                       <p>Empty</p>
                       <% 
                     }
              } finally {
                query.closeAll();}
           pm.close();

       }catch(Exception ex) {...}

异常:java .lang.ClassCastException:java.lang.String 无法转换为 com.google.appengine.api.users.User

我应该如何清除 PersistenceManager 中的所有数据?

请帮忙

I'm created Data Class and store data using PersistenceManager, but later I edited my Data Class and now i have problem with share data
I'm trying delete this objects (pm.deletePersistent(e)) but I'have exception :

javax.jdo.JDOUserException: One or more instances could not be deleted NestedThrowables: org.datanucleus.jdo.exceptions.ClassNotPersistenceCapableException: The class "The class "java.lang.Class" 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

that's my Data Class :

import com.google.appengine.api.datastore.Key;
import java.util.ArrayList;
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable

public class Task {
        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key key;

    @Persistent
    private String author;

    @Persistent
    private String task;

    @Persistent
    private Date date;

    @Persistent
    private String note;

    @Persistent
    private ArrayList<String> label; 

    @Persistent
    private int numberoflist;





    public Task (String author, String task,String note, Date date, int numberoflist)
    {
        this.author=author;
        this.task=task;
        this.date=date;
        this.numberoflist=numberoflist;
        this.note=note;
    }

that's my .jsp file, but deletePersistentAll(Task.class) or pm.deletePersistent(e) doesn't work because class Task has changed (one field changed type from User to String)

 try{                   
        PersistenceManager pm = PMF.get().getPersistenceManager();  
        pm.flush();
        Query query = pm.newQuery(Task.class);
        query.declareParameters("String authorParam");
        List<Task> results = (List<Task>) query.execute("user@mail");
            try
            {
                 if (results.iterator().hasNext())
                 {
                    for (Task e : results) 
                    {
                      pm.deletePersistent(e);
                      %>
                      <p><%= e.getTask() %> </p>
                      <%
                    }
                 }else 
                     {
                       %> 
                       <p>Empty</p>
                       <% 
                     }
              } finally {
                query.closeAll();}
           pm.close();

       }catch(Exception ex) {...}

exception : java.lang.ClassCastException: java.lang.String cannot be cast to com.google.appengine.api.users.User

what shoud I do to clear all data from PersistenceManager?

plz help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一向肩并 2024-09-22 06:18:33
  1. 你之前尝试过flush()
    删除?

  2. 您是否尝试确定
    e 有 pm 正在存储的类类型吗?

另外,请在此处发布完整的代码,或至少片段。

问候
尤金

  1. Did you try flush() before
    deleting?

    1. Did you try determine the
      e has class type that pm is storing?

Also, post here the full code please, or snippet as minimum.

Regards
Eugene

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文