【问题标题】:The serializable class X does not declare a static final serialVersionUID field of type long可序列化类 X 未声明 long 类型的静态最终 serialVersionUID 字段
【发布时间】:2015-01-26 17:13:43
【问题描述】:

我正在编写一个从 play.db.ebean.Model 扩展的 Play 框架实体,并从 eclipse 中收到此警告:

The serializable class user does not declare a static final serialVersionUID field of type long

谁能给我解释一下? play.db.ebean.Model (http://www.playframework.com/documentation/2.0.3/api/java/play/db/ebean/Model.html) 没有实现可序列化,我的 User 类也没有,所以我不明白为什么 eclipse 会抛出警告。

这是我的代码的重要部分:

package models;

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

import javax.persistence.Entity;
import javax.persistence.Id;

import crypto.PasswordHash;
import play.Logger;
import play.db.ebean.Model;
import play.data.validation.*;

@Entity
public class User extends Model {

    @Id
    @Constraints.Email
    private String email;
    @Constraints.Required
    private String name;
    @Constraints.Required
    @Constraints.MinLength(5)
    private String password;
    @Constraints.Min(0)
    private Integer rating;

    ...

}

【问题讨论】:

标签: java jakarta-ee serialization model playframework


【解决方案1】:

尽管在您链接的 javadoc 中没有这样说,play.db.ebean.Model 实现了 com.avaje.ebean.bean.EntityBean(请参阅 https://github.com/playframework/play-ebean/blob/master/play-ebean/src/main/java/play/db/ebean/Model.java),它又扩展了 java.io.Serializable(请参阅 http://www.avaje.org/static/javadoc/pub/com/avaje/ebean/bean/EntityBean.html)。所以,Eclipse 是正确的。

【讨论】:

    猜你喜欢
    • 2014-05-05
    • 2014-01-24
    • 2013-08-29
    • 2013-02-09
    • 2010-12-03
    • 2013-01-26
    • 2011-01-18
    • 2016-11-08
    • 1970-01-01
    相关资源
    最近更新 更多