Marcos J.C Kichel
Marcos J.C Kichel

Reputation: 7219

Design pattern for modular application (how to reuse entities)

I have the following scenario:

  1. A JAX-RS Webservice that is responsable for the business logic and database interactions.
  2. A webapp that will be used by the end users.
  3. A webapp that will be used by administrators.

My problem is that I want to reuse the entities from the webservice on the other apps, but it is highly wrapped with frameworks like JPA, JAX-RS, CDI, among others... So I am having a hard time to isolate them. What I want is to know the best workaround and why should I use it instead of others.

Upvotes: 0

Views: 270

Answers (2)

cslysy
cslysy

Reputation: 830

Maybe DTO is the way to go (with support from some object mapper library like Dozer)

Please take a look at following article for more details: http://zezutom.blogspot.com/2012/02/thoughts-on-data-transfer-objects.html

Upvotes: 3

Raedwald
Raedwald

Reputation: 48616

Write you entity objects as Plain Old Java Objects (POJOs), with proper constructors, setters, etc. Apply the annotations that allow the JPA to persist them and do the object to relational mapping in such a way that, if those annotations were all stripped away you could still create and manipulate those objects fully, using the public methods of the class. It can be helpful if you create the POJO first, then add the annotations afterwards.

As the POJOs stand alone they are not at all part of your repository layer. You can use them without using the JPA at all.

Upvotes: 0

Related Questions