Announcement Announcement Module
Collapse
No announcement yet.
very hard to diagnose problem with OSIV Filter and LazyInitException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • very hard to diagnose problem with OSIV Filter and LazyInitException

    i have a spring/hibernate/struts app -- standard setup on jboss 4.x/linux/apache.

    99.9% of the time, app runs great, then once in a while it throws lazyinitializationexception. i have no clue as to why it might be doing throwing the lazyinitexception with an OSIV filter.
    • we do have some jstl import statements here and there, e.g. <c:import url="${ssiurl}" />
    • we do updates to the DB in one place in the app only/on one screen


    web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    	<filter>
    		<filter-name>hibernateFilter</filter-name>
    		<filter-class>			org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    		</filter-class>
    	</filter>
    	<filter-mapping>
    		<filter-name>hibernateFilter</filter-name>
    		<url-pattern>/*</url-pattern>
    		<dispatcher>REQUEST</dispatcher>
    	</filter-mapping>
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			WEB-INF/applicationContext.xml
    		</param-value>
    	</context-param>
    	<listener>
    		<listener-class>
    			org.springframework.web.context.ContextLoaderListener
    		</listener-class>
    	</listener>
    	<servlet>
    		<servlet-name>action</servlet-name>
    		<servlet-class>
    			org.apache.struts.action.ActionServlet
    		</servlet-class>
    		<init-param>
    			<param-name>config</param-name>
    			<param-value>/WEB-INF/struts-config.xml</param-value>
    		</init-param>
    		<init-param>
    			<param-name>debug</param-name>
    			<param-value>3</param-value>
    		</init-param>
    		<init-param>
    			<param-name>detail</param-name>
    			<param-value>3</param-value>
    		</init-param>
    		<load-on-startup>0</load-on-startup>
    	</servlet>	
    	<servlet-mapping>
    		<servlet-name>action</servlet-name>
    		<url-pattern>*.do</url-pattern>
    	</servlet-mapping>
    	<error-page>
    		<exception-type>
    			org.hibernate.LazyInitializationException
    		</exception-type>
    		<location>/fatal_error.jsp</location>
    	</error-page>
    	<error-page>
    		<exception-type>java.lang.Exception</exception-type>
    		<location>/fatal_error.jsp</location>
    	</error-page>
    	<error-page>
    		<error-code>500</error-code>
    		<location>/fatal_error.jsp</location>
    	</error-page>
    </web-app>
    appcontext.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
    	<bean id="dataSource"
    		class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiName" value="java:FOO" />
    		<property name="cache" value="false" />
    		<property name="proxyInterface" value="javax.sql.DataSource" />
    	</bean>	
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="configLocation">
    			<value>classpath:hibernate.cfg.xml</value>
    		</property>
    	</bean>
    	<bean id="transactionManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref local="sessionFactory" />
    		</property>
    	</bean>
    	<bean id="fooDao" 
    	
    	  snip
    	</bean>	
    	<bean id="fooService"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager">
    			<ref local="transactionManager" />
    		</property>
    		<property name="target">
    			<bean id="fooServiceTarget"
    				class="bar">
    				<property name="fooDao" ref="fooDao" />				
    			</bean>
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="save*">PROPAGATION_REQUIRED</prop>
    				<prop key="record*">PROPAGATION_REQUIRED</prop>
    				<prop key="remove*">PROPAGATION_REQUIRED</prop>
    				<prop key="*">PROPAGATION_SUPPORTS,readOnly</prop>
    			</props>
    		</property>
    	</bean>
    
    	
    </beans>
    struts
    Code:
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
    	<!-- ========== Form Bean Definitions  -->
    	<form-beans>
    	</form-beans>
    	<!-- ========== Global Forward Definitions  -->
    	<global-forwards>
    		<forward name="home" path="/index.jsp" redirect="true" />
    	</global-forwards>
    	<!-- ========== Action Mapping Definitions  -->
    	<action-mappings>
    		<!-- action forwards -->
    
    
    	</action-mappings>
    	<controller
    		processorClass="com.acme.MyRequestProcessor" />
    	<message-resources
    		parameter="config/s_resources"
    		null="false" />
    </struts-config>

  • #2
    For such a case, try to profile the application or turn logging on, on the hibernate package and let the application run.
    I've had one such case some time ago which was caused by usage of AJAX. In some cases, depending on the user interaction, the Ajax page triggered several hibernate requests which were executed asynch but on the same hibernate session.
    If the first request ended before the rest, a LIE was thrown.
    Since this was a concurrency problem, it was quite hard to catch since we couldn't reproduce it.

    Comment

    Working...
    X