使用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
.