Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA POJO as Data Object

Tags:

java

jpa

What is the best practice in using JPA Entities?

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?

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

like image 592
Tazzy531 Avatar asked Sep 17 '09 21:09

Tazzy531


1 Answers

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" (original link currently offline):

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

like image 192
Pascal Thivent Avatar answered Sep 28 '22 07:09

Pascal Thivent