JPA POJO作为数据对象 [英] JPA POJO as Data Object

查看:186
本文介绍了JPA POJO作为数据对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JPA实体的最佳做法是什么?

What is the best practice in using JPA Entities?

由于JPA实体只是POJO,因此将对象用作其他部分的数据对象是否合适?系统或应该将它们转换为另一个数据对象?

Since JPA entities are just POJOs, is it considered appropriate to use the object as a data object in other parts of the system or should I convert them to another data object?

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

Is it acceptable to use the JPA Entity POJOs in other parts of the system unrelated to JPA?

推荐答案

实体现在自己能够传输自己的数据,为什么还要把它们转换成别的呢?换句话说,我倾向于同意 DTO在EJB 3.0中的AntiPattern

Entities are now themselves capable of transporting their own data so why bother converting them into something else? In other words, I tend to agree with DTO an AntiPattern in EJB 3.0:


EJB 3.0之前的EJB规范中实体Bean的重量级特性导致使用设计模式,如数据传输对象(DTO)。 DTO成为轻量级对象(首先应该是实体bean本身),用于跨层发送数据。 [...]

The heavy weight nature of Entity Beans in EJB specifications prior to EJB 3.0, resulted in the usage of design patterns like Data Transfer Objects (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规范使Entity bean模型与Plain old Java object(POJO)相同。使用这个新的POJO模型,您将不再需要为每个实体或一组实体创建DTO。如果要跨层发送EJB 3.0实体,只需实现 java.io.Serialiazable

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.

这篇关于JPA POJO作为数据对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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