Note that there are some explanatory texts on larger screens.

plurals
  1. POorg.hibernate.LazyInitializationException when migrating webapp to JSF 2.1 & RichFaces 4
    primarykey
    data
    text
    <p>I know this question has been asked a lot, but the strange thing here is that I had no problems when using jsf 1.1 / richfaces 3, along with hibernate 3.7 and spring 2.5.</p> <p>Now that I migrated my front-end to jsf 2.1 / richfaces 4 (hibernate and spring remained the same) the following exception appears when I try to access a collection marked as "lazy=true" in hibernate mapping config:</p> <pre><code>org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.mu.afs.Afi.cods, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97) at org.hibernate.collection.PersistentBag.size(PersistentBag.java:225) at javax.faces.model.ListDataModel.isRowAvailable(ListDataModel.java:91) at javax.faces.model.ListDataModel.setRowIndex(ListDataModel.java:105) </code></pre> <p>The collection that I try to reach is referenced by a <code>rich:datatable</code> in the same xhtml that the <code>Afi</code> entity; Here is the part of the xhtml that tries to access the collecion upon an ajax request of a master table:</p> <pre><code>&lt;rich:extendedDataTable id="tableCods" selectionMode="single" selection="#{afiBean.codSelected}" style="width: 100%; height: 100px" value="#{afiBean.selectedAfi.cods}" var="cod"&gt; ... &lt;rich:column width="50px" style="text-align: right;"&gt; &lt;f:facet name="header"&gt;&lt;h:outputText value="Months"/&gt;&lt;/f:facet&gt; &lt;h:outputText value="#{cod.months}" /&gt; &lt;/rich:column&gt; &lt;rich:column width="80px" style="text-align: right;"&gt; &lt;f:facet name="header"&gt;&lt;h:outputText value="Cap" /&gt; &lt;/f:facet&gt; &lt;h:outputText value="#{cod.cap}"&gt; &lt;f:convertNumber pattern="######,##0.00" locale="es_AR" /&gt; &lt;/h:outputText&gt; &lt;/rich:column&gt; &lt;rich:column width="200px" style="text-align: center;"&gt; &lt;f:facet name="header"&gt;&lt;h:outputText value="Class"/&gt;&lt;/f:facet&gt; &lt;h:outputText value="#{cod.clazz}" /&gt; &lt;/rich:column&gt; ... </code></pre> <p></p> <p>Here is my web.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"&gt; ... &lt;filter&gt; &lt;filter-name&gt;sessionFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.orm.hibernate3.support.OpenSessionInViewFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;sessionFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt; &lt;dispatcher&gt;FORWARD&lt;/dispatcher&gt; &lt;dispatcher&gt;INCLUDE&lt;/dispatcher&gt; &lt;/filter-mapping&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; &lt;servlet&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; ... </code></pre> <p></p> <p>This is part of my application-context.xml:</p> <pre><code>... &lt;bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="sessionFactory" /&gt; &lt;/bean&gt; &lt;bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt; &lt;property name="transactionManager" ref="txManager" /&gt; &lt;property name="transactionAttributes"&gt; &lt;props&gt; &lt;prop key="save*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;prop key="store*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;prop key="get*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;prop key="read*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;prop key="load*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;prop key="*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; ... </code></pre> <p>The service that is accessing the <code>Afi</code> entity is defined as follow:</p> <pre><code>&lt;bean id="afiService" parent="txProxyTemplate"&gt; &lt;property name="proxyInterfaces" value="com.mu.afs.services.AfiService" /&gt; &lt;property name="target"&gt; &lt;bean class="com.mu.afs.services.impl.AfiServiceImpl"&gt; &lt;property name="afiDao" ref="afiDao" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="afiliadosDao" class="com.mu.afs.dao.impl.HibernateAfiDaoImpl" parent="hibernateDaoSupport"&gt; &lt;/bean&gt; </code></pre> <p>I would really appreciate if someone can throw some light on this issue. I dont know whether is related to a migration issue or if there is a problem with this configuration and was somehow "masked" with a previous version of jsf and richfaces. </p> <p>I tried to put here any relevant information that I thought it would help without boring and overwhelm the reader, but let me know if something is missing here.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload