Hibernate表类是否需要Serializable? [英] Do Hibernate table classes need to be Serializable?

查看:88
本文介绍了Hibernate表类是否需要Serializable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个使用Hibernate 3.0连接到SQL Server数据库的Websphere Portal项目。

I have inherited a Websphere Portal project that uses Hibernate 3.0 to connect to a SQL Server database.

这个项目中大约有130个Hibernate表类。他们都实现了Serializable。他们都没有声明serialVersionUID字段,所以Eclipse IDE显示了所有这些类的警告。

There are about 130 Hibernate table classes in this project. They all implement Serializable. None of them declare a serialVersionUID field, so the Eclipse IDE shows a warning for all of these classes.

这些类实际上是否需要实现Serializable? >
如果是这样,是否有任何工具可以将生成的serialVersionUID字段一次性添加到大量的类中(仅用于使警告消失)?

Is there any actual need for these classes to implement Serializable?
If so, is there any tool to add a generated serialVersionUID field to a large number of classes at once (just to make the warnings go away) ?

推荐答案


这些类实际上是否需要实现Serializable?

Is there any actual need for these classes to implement Serializable?

JPA规范(JSR 220)总结得非常好(对于Hibernate也一样):
$ b

The JPA spec (JSR 220) summarizes it pretty well (the same applies to Hibernate):


2.1对实体类的要求



(...)

2.1 Requirements on the Entity Class

(...)

如果一个实体实例被作为分离对象传递例如,通过远程接口),实体类必须实现 Serializable 接口。

If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.



所以,严格来说,这不是一个要求减少你需要分离的实体通过线路发送到另一个层,被迁移到另一个集群节点,存储在HTTP会话中等。


So, strictly speaking, this is not a requirement unless you need detached entities to be sent over the wire to another tier, to be migrated to another cluster node, to be stored in the HTTP session, etc.


如果是这样,是否有任何工具可以将生成的serialVersionUID字段一次添加到大量的类中

If so, is there any tool to add a generated serialVersionUID field to a large number of classes at once

I认为可以使用串行版本(Ant)任务对其进行批处理。

I think that you could batch this with the Serial version (Ant) Tasks.

这篇关于Hibernate表类是否需要Serializable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆