Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my experience on a similar architecture, for a quite big project, DTOs are unavoidable and should be used when necessary. </p> <p>Working with detached entities, especially when they have multiple associations with other entities, not only causes performance problems due to the database loading and serialization, but also a huge complexity. Indeed, unless the code is extremely well documented, it's hard to know in the presentation layer whether a given association is loaded or not, which causes a whole lot of lazy initialization exceptions.</p> <p>It's even worse if you send back serialized detached entities from the presentation layer to the service layer, because then you end up with code using a mix of detached and attached entities, which makes things even more complex.</p> <p>My advices would thus be:</p> <ul> <li>transfer entities from the service layer to the UI layer if the entity is simple and the UI layer doesn't need too many loaded associations. Always document which of the associations are initialized, and which are not. If too many associations, use DTOs, and ad hoc queries to load the necessary data from the database.</li> <li>transfer DTOs from the service layer to the UI layer when a big number of entities are needed (for example, the result of a search form returning O(100) results or more). Use an ad hoc query to load the requested data.</li> <li>avoid transferring entities from the presentation layer to the service layer. If you do, make sure that the first thing you do in the service layer is reloading an attached version of the entity from the database, or merging the received entity, in order to always work with attached entities. Debugging a lazy initialization exception thrown in the service layer and cause by the use of a detached entity that has been loaded several minutes ago by a previous screen is not a piece of pleasure.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload