Organizational Research By

Surprising Reserch Topic

web architecture mvc lazy initialization data transfer objects open session

web architecture mvc lazy initialization data transfer objects open session  using -'hibernate,spring,architecture,web-architecture'

What flaws do you see in the following design, (and what would be your ideal architecture suggestion) for a typical web 3-tier application?

My current blueprint approach is very roughly this (assuming Java, Spring, Hibernate, JSP)


Stateless, potentially wrapped with a read only transaction (to avoid lazy init exceptions), get's entities from persistence storage via the service only, passes them to the view as the model. Conducts business logic on them (should the BL be in the service layer only?), passes back to the service layer for persistence if required.

Pros: For read-only transaction wrapping - only one connection, no redundant hits for the same persistent entity, utilizes query cache better, service layer shouldn't "know" request parameters, or required init graph span, avoid lazy init exceptions.

Cons: The read-only transaction approach can be risky, controllers are not the ideal Business Logic hanging place... very hard to do JUnits (your input is a request...)


Non transactional (access to non lazy collections / members will result in a lazy init exception)


The view author shouldn't affect by mere dot notation the performance of the application (e.g. cause N+1 selects due to lazy initializing a large collection.
Also in disconnected clients (Flex, or other Rich Clients) lazy initialization remotely is either non supported, or just not a smart thing to do

Cons: the controller / service / DAO must prepare carefully the right graph of entities for the view, and may be overshooting (performance) / undershooting (lazy init exception). a myriad of server side methods can cause clutter as there is a Cartesian product to the number of permutations an entity graph can be initialized


Using the persistent objects as is, (no data transfer objects), state is saved in the session.

Pros: no need to rewrite POJOs, reuse of existing entities, session state is more secure than hidden fields state handling.

Cons: Bad for disconnected frameworks, risk of saving stale disconnected objects, risk of locking issues, overriding other's data, requires optimistic locking sometimes.


Transactional, doesn't know the request scope, calls a DAO layer for actual persistence storage access. this is where the BL should classically be, but it seems the BL leaks to the controller side over and over.


Contains atomic persistence storage facade, ignorant of the BL, or any context

Finally, the question:

What would you fix in the above architecture?

Do you think (like me) it is a quite common approach (with some minor differences, such as open session in view, etc)? Or is it the first time you see it and I'm doing something terribly wrong (or right)?

How do you solve it in your applications? Do you use your entity POJOs also for your model and view? or do you wire it up to simpler UI beans (all fully initialized and secure)?

This may be a subjective question, but I'm sure there are clear best practice design patters that cluster to one, two or three max general "religions".

asked Oct 6, 2015 by r3tt
0 votes

Related Hot Questions

4 Answers

0 votes
answered Oct 6, 2015 by yashwantpinge
0 votes
answered Oct 6, 2015 by maurya
0 votes
answered Oct 6, 2015 by nimisha.jagtap
0 votes
answered Oct 6, 2015 by akhilesh