Reputation: 4306
I have project in which i have
and also I have DTO for every Entity,
@Entity
@Table(name = "insurance_config")
public class InsuranceConfiguration {
and DTO
public class InsuranceConfigurationDTO {
from architecture perspective what is the best practice to convert DTO to/from Entity ?
In which layer the conversion should take place?
Should I put the conversion methods inside the DTO/Entity or in separate class ?
Upvotes: 4
Views: 3910
Reputation: 776
You should introduce interface layers between the web/service/persistence layer and avoid transitive dependencies. And the transformation logic should not be included in the DTO's rather in a different class, but that's my opinion.
For better understanding, I created a simple UML for this:
(PS.: I could post this project to github if needed)
Upvotes: 7
Reputation: 473
here is a link where you get to know about the TOA design pattern. I think this is what you looking for. Here you call a dao class and after you get an object or list of object you can call a Dozer mapper which you can use for convert from entity to dto and it is may be in util package or mapper package. I think the best is the Business layer or may be the Persistence...but of course not the Presentation..
Upvotes: 2