Are there more methods to avoid LazyInitializationExceptions inside a Hibernate web application besides while using OpenSessionInView pattern? What are the disadvantages to presenting OpenSessionInView?

When focusing on our web programs, we usually decide in advance which objects/fields is going to be necessary for the vista pages and make certain that the objecs are correctly initialized in the model before dispatching towards the view.

This can be done in (a minimum of) 3 ways:

  1. fetching qualities using eager strategy (i.e. with FetchMode.JOIN, if you are while using Criteria API)
  2. clearly initializing qualities (i.e. with Hibernate.initialize(property))
  3. unconditionally initializing qualities by calling the right property accessor

Concerning the disadvantages of OpenSessionInView, perhaps you have examined this page?

Typically the easiest method to handle the issue, without creating a global decision to complete eager fetching is by using the "fetch" keyword similar to the hql query.

From http://www.hibernate.org/hib_docs/reference/en/html/queryhql-joins.html

Additionally, a "fetch" join enables associations or collections of values to become initialized together with their parent objects, utilizing a single choose. Many of the helpful within the situation of the collection. It effectively overrides the outer join and lazy terms from the mapping apply for associations and collections. See Section 19.1, “Fetching strategies” to learn more.

from Cat as cat inner join fetch cat.mate left join fetch cat.cats

Change to JBoss Seam.

The Seam framework is well architected through the men that developed Hibernate.

Despite outdoors Session because, you might still possess some problems. For the way complex your internet application is, Open Session Because doesn't handle every case. I have had difficulties with exhibiting data too (within the UI) as fetching organizations throughout a quarta movement job for example delivering an e-mail.

Hibernate already smartly brings data, altering the fetch mode can lead to performance degradation. Not just that, but you're escaping convention and can muck your project with extraneous configuration particulars.

Walter