加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – JPA POJO作为数据对象

发布时间:2020-12-14 05:10:09 所属栏目:Java 来源:网络整理
导读:使用JPA实体的最佳做法是什么? 由于JPA实体只是POJO,在系统的其他部分使用该对象作为数据对象还是将其转换为另一个数据对象是否合适? 在与JPA无关的系统的其他部分使用JPA实体POJO可以接受吗? 解决方法 实体现在自己能够运送自己的数据,所以为什么要把它
使用JPA实体的最佳做法是什么?

由于JPA实体只是POJO,在系统的其他部分使用该对象作为数据对象还是将其转换为另一个数据对象是否合适?

在与JPA无关的系统的其他部分使用JPA实体POJO可以接受吗?

解决方法

实体现在自己能够运送自己的数据,所以为什么要把它们转换成别的东西?换句话说,我倾向于同意 DTO an AntiPattern in EJB 3.0:

The heavy weight nature of Entity Beans in EJB specifications prior to EJB 3.0,resulted in the usage of design patterns like 07001 (DTO). DTOs became the lightweight objects (which should have been the entity beans themselves in the first place),used for sending the data across the tiers. […]

EJB 3.0 spec makes the Entity bean model same as Plain old Java object (POJO). With this new POJO model,you will no longer need to create a DTO for each entity or for a set of entities. If you want to send the EJB 3.0 entities across the tier make them just implement java.io.Serialiazable.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读