Using a DTO or Value Object pattern to combat lazy loading exceptions

Only architectural issue in Java / Hibernate / Spring / Mysql stack

Should I use the OpenSessionInView template or use DTO objects at my service level to withstand lazy loading errors.

Is it good to return Domain / Entity objects from the service level? Or it is good practice to return DTO objects which are then serialized in xml / json at the web service level.

+4
source share
1 answer

I follow a very simple rule:

DTO is more or less a transfer from one domain to another. This means that I use DTO when I have a physical separation between two layers.

Meaning in case you have a JSP, you can use the OpenSessionInView template to avoid a lot of work on model translation, etc.

+1
source

Source: https://habr.com/ru/post/1414373/


All Articles