title: Lazy Initialisation with OpenEntityManagerInViewFilter?
body: <p>I have a little already working JBoss webapp, and a Lazy initialisation problem.
  Therefore I was advised to investigate in Spring and use <code>OpenEntityManagerInViewFilter</code>.</p>
  
  <p>Nevertheless I still get the error, hope you could help me?
  What else do I have to change in my app to make use of the Spring OEM Filter?</p>
  
  <p>My setup is like this:</p>
  
  <pre><code>@Entity
  class Customer;
  
  @Stateless
  @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
  class DaoService {
    @PersistenceContext
    EntityManager em;
  }
  
  @Named
  @RequestScoped
  class CustomerFacade;
  </code></pre>
  
  <p>+jsf stuff. </p>
  
  <pre><code>[javax.enterprise.resource.webcontainer.jsf.context] (http--127.0.0.1-8080-1) org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: domain.Customer.customerList, no session or session was closed
  </code></pre>
  
  <p>I set it up like this:
  web.xml</p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;
          OpenEntityManagerInViewFilter
      &lt;/filter-name&gt;
      &lt;filter-class&gt;
          org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
      &lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;singleSession&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;flushMode&lt;/param-name&gt;
          &lt;param-value&gt;AUTO&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/filter&gt;
  &lt;!-- Include this if you are using Hibernate --&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;OpenEntityManagerInViewFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  
  &lt;!-- Spring config --&gt;
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>applicationContext.xml:</p>
  
  <pre><code>&lt;bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /&gt;
      &lt;/property&gt;
      &lt;property name="jpaProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.transaction.manager_lookup_class"&gt;
                  org.hibernate.transaction.JBossTransactionManagerLookup
              &lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>persistence.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0"
     xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
          http://java.sun.com/xml/ns/persistence
          http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
     &lt;persistence-unit name="primary"&gt;
        &lt;!-- If you are running in a production environment, add a managed 
           data source, the example data source is just for proofs of concept! --&gt;
        &lt;jta-data-source&gt;java:jboss/datasources/ExampleDS&lt;/jta-data-source&gt;
        &lt;properties&gt;
           &lt;!-- Properties for Hibernate --&gt;
           &lt;property name="hibernate.hbm2ddl.auto" value="create-drop" /&gt;
           &lt;property name="hibernate.show_sql" value="false" /&gt;
        &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Thats basically all the setup. And everything is working apart from the lazy loading problem.</p>