Quote:
1.
JSP to load list -> EJB -> DAO(load list)
JSP to display element
JSP to display lzay entities -> EJB -> DAO (load lazy entity)
This is definitely not the case. The proxy object has a reference to a Session (~Database connection). If it needs to be initialized, it uses this Session to do that, it never accesses EJB-s automatically (how could it?). If the Session is disconnected, initialization will simply fail with an exception, it will not call EJBS-s, it won't attempt to connect to the database. Sessions are only opened when you say so specifically. (Well, except in managed environments, but still, there you specify this declaratively)
Quote:
2.
JSP to load list -> EJB -> DAO (load list ,load lazy entities)
if 1 is true, there will be 2 round trip from JSP to EJB to DAO
if 2 is true , how does hibernate(in DAO) knows JSP WILL use those lazy entities.
Hibernate does not know, and I think it does not
care. If you try using uninitialized proxies, you will end up with an exception.
You will need to
specifically initialize proxies at a point in your code where you still have an open session. If that place is the EJB, thats where it needs to be done. If your session is still open in your JSP, you can let lazy initialization happen there (don't distribute your application on different containers in that latter case, though).
I have the impression that you think lazy objects can do all kinds of magic for you. Well, that is not the case. Lazy objects have many advantages, but automagically fetchin data without database connection is not one of them. In fact, that would be totally confusing if they just tried to open database connections as they see fit.