I must start by saying that I am developing for 10 years on AS400 and me half a year ago when it just somehow allowed the time to occupy myself with J2EE as a hobby. Especially EJBs raise the claim so that developers only have to worry about business logic. Especially for Web applications, which I would lie in the heart (no configuration required on the local client) but this seems not to apply.
Glaring example:
Customer name is displayed in list. Later, should also address will be displayed. However, the program throws LazyInitializationException because Hibernate session exists only for access to customer-DAO. Later, no session is available to load address. In Spring there is for it then the OpenSessionInViewFilter. If that is once installed, it is difficult to eliminate later. Object, for example, customer notice for several requests. Also this filter helps but not if the following happened: customers register, log out again, then back on. Select an order and would like to receive printed confirmation of order. Download and place ads in two different types of request. After sign request is terminated and OpenSessionInViewFilter closes application. When printing customer order confirmation is again detached.
Solution options:
A Hibernate session per session is not possible, since application at faults. Eager-Loading: not allowed. However, one can initialize the object as a compromise in Hibernate, for example Hibernate.initialize (customer.getAdress ()). In a HQL query we then won again the required lazy loading. Only primary key: Save technically you have to talk about it often with database. Lock - Lock method via client is reconnected to Hibernate session. Hibernate Long Session forces: to implement the management of applications transactions. Perhaps the lesser evil!!
You can add the comments as well as doubts about this topic here.!!
Bookmarks