无法获取类包的类型签名.Line

时间:2014-07-28 20:31:08

标签: java gwt objectify

使用GWT和Objectify 5.0.3版实现了该示例。 当我尝试保存Document的实例时会产生这种情况。 我得到错误:

无法获取类Line

的类型签名

你有一个想法吗?

@SuppressWarnings("serial")

@Entity
public class GenericEntity implements Serializable {

     @Id  protected Long id;

}



@SuppressWarnings("serial")

@Entity

public class Document extends GenericEntity implements Serializable {

     @Index  private String name;

     @Serialize  private List<Session> sessions = new ArrayList<Session>();

}



@SuppressWarnings("serial")

@Entity

public class Session extends GenericEntity implements Serializable {

     private Date date;

     @Serialize  private Vector<Line> transectsH = new Vector<Line>();

     @Serialize  private HashMap<Point, Line> mapperHorizontalLines = newHashMap<Point, Line>();

}



@SuppressWarnings("serial")

@Entity

public class Point extends GenericEntity implements Serializable {

     private double x;

     private double y;

}



@SuppressWarnings("serial")

@Entity

public class Line extends GenericEntity implements Serializable {

     private Point coordinate;

     private Image image;

     private Object data;

}

2 个答案:

答案 0 :(得分:1)

当您尝试序列化某些内容时,您将从GWT获取异常。可能是因为GWT-RPC无法序列化Object类型的声明。

答案 1 :(得分:0)

在客观化中,您可以定义相关实体类的多态层次结构,如下所示。请提供以下代码,告诉我们您的工作方式;警告:代码尚未经过测试 - 所有这些都是匆忙完成的,我很害怕!

请记住,如果类的超类已经在Java中实现了Serializable接口,那么它已经在Java中可以序列化 - 不需要子类来实现Serializable

请注意,您必须显式注册所有子类(使用@Subclass注释的子类),否则您将收到错误!

我建议阅读涵盖多态性的客观文档中的部分Objectify Entities Polymorphism

@SuppressWarnings("serial")
@Entity
public class GenericEntity implements Serializable {

     @Id  protected Long id;
}


@SuppressWarnings("serial")
@Subclass
public class Document extends GenericEntity {

     @Index  private String name;

     @Serialize  private List<Session> sessions = new ArrayList<Session>();
}


@SuppressWarnings("serial")
@Subclass
public class Session extends GenericEntity {

     private Date date;

     @Serialize  private Vector<Line> transectsH = new Vector<Line>();

     @Serialize  private HashMap<Point, Line> mapperHorizontalLines = newHashMap<Point, Line>();
}


@SuppressWarnings("serial")
@Subclass
public class Point extends GenericEntity {

     private double x;

     private double y;
}


@SuppressWarnings("serial")
@Subclass

public class Line extends GenericEntity {

     private Point coordinate;

     private Image image;

     private Object data;
}