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

标签 java gwt google-cloud-datastore

我正在使用带有 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/

相关文章:

java - 这是一些天才的东西还是简单的糟糕代码?

java - 向图像添加 Action 监听器

database - 如何更新 Google App Engine NDB 对象上的数据,以便它可以同时进行多次写入

java - 如何在处理中一次渲染列表中的 1 个以上对象?

java - 为什么可以在 Java 中记录 OutOfMemory 错误?

java - 如何突出显示 GWT 文本框

css - 如何更改我的 GWT 列表框样式

java - 图像包位置

java - 如何使用java从Google App Engine数据存储中加载值以进行OR操作

google-app-engine - 如何在 Go AppEngine 中将数据存储查询存储到内存缓存?