gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:18:38 26 4
gpt4 key购买 nike

我创建了数据类并使用 PersistenceManager 存储数据,但后来我编辑了我的数据类,现在我在共享数据时遇到了问题我正在尝试删除此对象 (pm.deletePersistent(e)) 但我有异常(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

那是我的数据类:

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 中的所有数据?

求助

最佳答案

  1. 您之前是否尝试过flush()删除?
    1. 您是否尝试确定e 有 pm 存储的类类型?

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

问候尤金

关于java - 使用 PersistenceManager 删除对象时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3511635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com