How to convert Entity Bean to Value object?

I am developing a server system that provides services for both the client and the browser, I decided to use JPA to work with OR / Mapping to store the database. This leads to the Entity Bean class, which is vulnerable to the client, so I try to avoid this design using Value Objects and Data Transfer Objects. This means that I need POJOs, as well as mechanisms for exchanging POJO and Entity Bean classes on different system buses.

My question is: is there any mature design template or the specified EJB service can do this automatically? I really dislike creating some POJO-Entity Bean mappings that are hard to split and update.

Thank you in advance

+4
source share
2 answers

This leads to the Entity Bean class, so I try to avoid such a construct using Value Objects and Data Transfer Objects.

Why? What is the problem that justifies such cruel copying of code?

A “Data Transfer Object” and the misuse of the “Value Object” name are antipatterns that were needed with EJB 2 Entity Beans to avoid excessive server visits.

If you use JPA, you do not have a beans entity. Your POJO entities, and there is absolutely nothing wrong with exposing them to a client - in fact, this is one of the best things about JPA.

+4
source

You might want to look at Dozer , a bean that uses reflection to display beans based on field names. This gives you some protection against changes, since you can always specify mappings manually if one class changes, but you want to keep the mapped class the same.

+2
source

All Articles