Reputation: 7367
In the official documentation about the DAO pattern said that there were four main participants in the pattern.
BusinessObject
DataAccessObject
DataSource
TransferObject
Also there says:
The BusinessObject represents the data client. It is the object that requires access to the data source to obtain and store data. A BusinessObject may be implemented as a session bean, entity bean, or some other Java object, in addition to a servlet or helper bean that accesses the data source.
My question is why we can't use the Entity bean as a Transfer Object
? I thought it perfectly suits to the definition.
So essentially entity beans can be used both as BusinessObject
and TransferObject
, can they?
For instance, an entity:
@Entity
@Table(name="tbl")
public class User{
//Fields, Getters, Setters
}
What's wrong?
Upvotes: 1
Views: 74
Reputation: 21893
Yes, In modern technology stacks this is done. You can use the same POJO for both Business Object and Transfer Object. But there are limitations of this approach.
Because of these reasons it is recommended to have two sets of POJOs.
Upvotes: 1
Reputation: 4584
Entity is bounded to JPA session and will not work correctly when the session is closed (for example when it is sent to another server) - for example accessing lazy collections will throw an exception
Upvotes: 2