微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 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.

原文地址:https://www.jb51.cc/java/123291.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐