简体   繁体   中英

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM