Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to correctly implement OpenSessionInView with Spring 3.0 and Hibernate 3 (in liferay portlets)?
    primarykey
    data
    text
    <p>I have some problems in implementing the OpenSessionInView pattern. From various resources on the web i configured my application in this way: <br/> 1) in my dispatcher-servlet.xml I have an interceptor that should get all my requests with a spring class OpenSessionInViewInterceptor: <br/></p> <pre><code>&lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt; &lt;property name="interceptors"&gt; &lt;list&gt; &lt;ref bean="openSessionInViewInterceptor"/&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="mappings"&gt; &lt;props&gt; &lt;prop key="index.htm"&gt;indexController&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactoryAnnotation"/&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>2) then I have configured transactions in my Service layer with AOP in this way: </p> <pre><code>&lt;aop:config&gt; &lt;aop:pointcut expression="execution(* it.jdk.crm.service..*Service.*(..))" id="gestioneComunicazioniOperation"/&gt; &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="gestioneComunicazioniOperation"/&gt; &lt;/aop:config&gt; &lt;tx:advice id="txAdvice" transaction-manager="txManager"&gt; &lt;tx:attributes&gt; &lt;tx:method name="get*" read-only="true"/&gt; &lt;tx:method name="find*" propagation="SUPPORTS" read-only="true"/&gt; &lt;tx:method name="save*" propagation="REQUIRED"/&gt; &lt;tx:method name="update*" propagation="REQUIRED"/&gt; &lt;tx:method name="delete*" propagation="REQUIRED"/&gt; &lt;tx:method name="*"/&gt; &lt;/tx:attributes&gt; &lt;/tx:advice&gt; &lt;bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="txManager"&gt; &lt;property name="sessionFactory"&gt; &lt;ref local="sessionFactoryAnnotation" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="txManager"&gt; &lt;property name="sessionFactory"&gt; &lt;ref local="sessionFactoryAnnotation" /&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>Is it possible that the two configurations are in conflict? I have a requirement that my Service layer (used in portlets) should be transaction-bounded, is it in conflict with the OpenSessionInView? If it is, then how can I prevent <code>LazyInitializationException</code> errors in my controllers?</p> <p>EDIT: the exception is occurring in the view, when i call</p> <p><code>&lt;c:forEach items="${communication.questions}" var="question" &gt;</code></p> <p>with exception </p> <p><code>ERROR [jsp:165] org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: it.*.Communication.questions, no session or session was closed</code></p> <p>and the code in the controller that calls the view is like: </p> <pre><code>@RequestMapping(params="action=dettagli") public ModelAndView dettagliComunicazione(@ModelAttribute("communication") Communication c) { Communication communication = null; try { communication = communicationService.findById(c.getId()); } catch (Exception ex) { } Hashtable l = new Hashtable(); l.put("communication", communication); return new ModelAndView("communication/details", l); } </code></pre> <p>that gets resolved in a file by the bean in dispatcher-servlet.xml: </p> <pre><code>&lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /&gt; </code></pre>
    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.
 

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