gpt4 book ai didi

java - ArrayList 在从谷歌数据存储区检索时抛出异常(使用 gwt、java)

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:04:03 25 4
gpt4 key购买 nike

我正在使用带有 java 和谷歌数据存储作为数据库的 Google Web Toolkit。实体类有 arraylist 并且在尝试从数据库中检索数据时出现异常:

Type 'org.datanucleus.sco.backed.ArrayList' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.

我正在使用 JPA。

实体代码:

 package com.ver2.DY.client;

import java.io.Serializable;
import java.util.ArrayList;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.gwt.user.client.rpc.IsSerializable;

@PersistenceCapable
public class ChatInfo implements Serializable, IsSerializable{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long topicId;

@Persistent
private String chatTopic;

@Persistent
private ArrayList<String> messages = new ArrayList<String>();

@Persistent
private boolean isFirstPost;

public ChatInfo()
{

}


public Long getTopicId() {
return topicId;
}
public void setTopicId(Long topicId) {
this.topicId = topicId;
}
public String getChatTopic() {
return chatTopic;
}
public void setChatTopic(String chatTopic) {
this.chatTopic = chatTopic;
}
public ArrayList<String> getMessages() {
return messages;
}
public void addMessage(String newMsg) {
messages.add(newMsg);
}

public boolean isFirstPost() {
return isFirstPost;
}
public void setFirstPost(boolean isFirstPost) {
this.isFirstPost = isFirstPost;
}

}

数据库类中的方法:

@Transactional
public ChatInfo[] getAllChat() {
PersistenceManager pm = PMF.get().getPersistenceManager();
List<ChatInfo> chats = null;
ChatInfo[] infos = null;
String query = "select from " + ChatInfo.class.getName();
try{
chats = (List<ChatInfo>) pm.newQuery(query).execute();


infos = new ChatInfo[chats.size()];
for(int i=0;i<chats.size();i++)
{
infos[i] = new ChatInfo();
infos[i] = (ChatInfo) chats.get(i);
}
}
finally{
pm.close();
}
return infos;

}

这有点奇怪,因为之前我能够插入和检索数据,但现在抛出异常。在网上搜索时,我发现我需要将 Arraylist 从某种 DataNucleus 类型转换为 java util,但不确定该怎么做。

最佳答案

异常是由于该类不在您的 GWT RPC 白名单(可序列化的类列表)中引起的。

我无法在您提供的任何示例代码中看到 org.datanucleas.sco.backed.ArrayList 的任何导入。

查看 this question有关 GWT 和 JPA 的更多信息。

关于java - ArrayList 在从谷歌数据存储区检索时抛出异常(使用 gwt、java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2687911/

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