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 ?
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)
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..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With