Hello,
I am using Spring Hibernate DAO support for my DAOS, and trying to initialize an object in the context, which uses such DAOS in the init-method. Although I am using an Hibernate Interceptor to avoid lazy fetching to fail in my unit tests and, it lokks like there is a problem while initializing my 'objectDefinitionSourceTarget' bean. The troublesome bean has a method that reads some values from the database.
The problem only gets there as I use init-method for 'objectDefinitionSourceTarget'. I have started to suspect about my configuration, since I turned off lazy fetching and stared to get an OutofMemory Exception while retrieving a few rows.
Here is my context:
The error, while loading the context isCode:<!-- DataSource Definition --> <bean id="mydataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://jgarcia:3306/seguridad</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>root</value> </property> </bean> <!-- Spring Data Access Exception Translator Defintion --> <bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator"> <property name="dataSource"><ref bean="mydataSource"/></property> </bean> <!-- Hibernate SessionFactory Definition --> <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> <property name="mappingResources"> <list> <value>co/com/unionsoluciones/seguridad/modelo/bo/Usuario.hbm.xml</value> <value>co/com/unionsoluciones/seguridad/modelo/bo/Url.hbm.xml</value> <value>co/com/unionsoluciones/seguridad/modelo/bo/Rol.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.cglib.use_reflection_optimizer">true</prop> <prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</prop> </props> </property> <property name="dataSource"> <ref bean="mydataSource"/> </property> </bean> <!-- Hibernate Transaction Manager Definition --> <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"> <property name="sessionFactory"><ref local="sessionFactory"/></property> </bean> <!-- Hibernate Template Defintion --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate.HibernateTemplate"> <property name="sessionFactory"><ref bean="sessionFactory"/></property> <property name="jdbcExceptionTranslator"><ref bean="jdbcExceptionTranslator"/></property> </bean> <!-- DAO's --> <bean id="rolDao" class="co.com.unionsoluciones.seguridad.modelo.dao.hibernate.RolDaoHibernateImpl"> <property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property> </bean> <bean id="urlDao" class="co.com.unionsoluciones.seguridad.modelo.dao.hibernate.UrlDaoHibernateImpl"> <property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property> </bean> <bean id="usuarioDao" class="co.com.unionsoluciones.seguridad.modelo.dao.hibernate.UsuarioDaoHibernateImpl"> <property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property> </bean> <!--<bean id="memoryAuthenticationDao" class="net.sf.acegisecurity.providers.dao.memory.InMemoryDaoImpl"> <property name="userMap"> <value> user=pass,ROLE_USER,ROLE_SUPERVISOR user1=pass,ROLE_USER user2=pass,ROLE_USER </value> </property> </bean>--> <bean id="unionAuthenticationDao" class="co.com.unionsoluciones.seguridad.modelo.dao.UnionAthenticationDao"> <property name="usuarioDao"> <ref local="usuarioDao"/> </property> </bean> <bean id="daoAuthenticationProvider" class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider"> <property name="authenticationDao"> <ref local="unionAuthenticationDao"/> </property> </bean> <bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderManager"> <property name="providers"> <list> <ref bean="daoAuthenticationProvider"/> </list> </property> </bean> <bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter"> <property name="authenticationManager"> <ref bean="authenticationManager"/> </property> <property name="authenticationFailureUrl"> <value>/login.jsp?error=1</value> </property> <property name="defaultTargetUrl"> <value>/</value> </property> <property name="filterProcessesUrl"> <value>/j_acegi_security_check</value> </property> </bean> <bean id="roleVoter" class="net.sf.acegisecurity.vote.RoleVoter"/> <bean id="accessDecisionManager" class="net.sf.acegisecurity.vote.UnanimousBased"> <property name="allowIfAllAbstainDecisions"> <value>false</value> </property> <property name="decisionVoters"> <list> <ref local="roleVoter"/> </list> </property> </bean> <bean id="securityEnforcementFilter" class="net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter"> <property name="filterSecurityInterceptor"> <ref bean="filterInvocationInterceptor"/> </property> <property name="authenticationEntryPoint"> <ref bean="authenticationEntryPoint"/> </property> </bean> <bean id="httpSessionIntegrationFilter" class="net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter"> <property name="context"><value>net.sf.acegisecurity.context.security.SecureContextImpl</value></property> </bean> <bean id="authenticationEntryPoint" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"> <property name="loginFormUrl"> <value>/login.jsp</value> </property> </bean> <bean id="filterInvocationInterceptor" class="net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor"> <property name="authenticationManager"> <ref bean="authenticationManager"/></property> <property name="accessDecisionManager"> <ref bean="accessDecisionManager"/></property> <property name="objectDefinitionSource"> <value> CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON PATTERN_TYPE_APACHE_ANT /secure/super/**=ROLE_SUPERVISOR /secure/**=ROLE_USER,ROLE_SUPERVISOR </value> </property> </bean> <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate.HibernateInterceptor"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <bean id="objectDefinitionSourceTarget" class="co.com.unionsoluciones.seguridad.modelo.bo.PathBasedFilterInvocationDefinitionMapUnion" init-method="init"> <property name="urlDao"> <ref bean="urlDao"/> </property> </bean> <bean id="objectDefinitionSource" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="target"><ref bean="objectDefinitionSourceTarget"/></property> <property name="proxyInterfaces"> <value>net.sf.acegisecurity.intercept.ObjectDefinitionSource</value> </property> <property name="interceptorNames"> <list> <value>hibernateInterceptor</value> </list> </property> </bean>
Notice the init method in the troublesome bean is as follows (it uses beans from the AppContext)[junit] Testcase: testActualizar(co.com.unionsoluciones.seguridad.mo delo.dao.TestUrlDao): Caused an ERROR
[junit] Error creating bean with name 'objectDefinitionSourceTarget' defined in class path resource [securityContext.xml]: Initialization of bean failed; nested exception is net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
[junit] org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'objectDefinitionSourceTarget' defined in class path resource [securityContext.xml]: Initialization of bean failed; nested exception is net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
[junit] net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
Please help! I am stuck and in a hurry....Code:public void init(){ List urls = this.urlDao.obtenerTodosUrls(); while (urls.listIterator().hasNext()) { Url url = (Url) urls.listIterator().next(); String urlPath = url.getUrl(); Set rols = url.getRols(); ConfigAttributeDefinition configAttributeDefinition = new ConfigAttributeDefinition(); while (rols.iterator().hasNext()) { Rol rol = (Rol) rols.iterator().next(); configAttributeDefinition.addConfigAttribute(new SecurityConfig(rol.getSpringRole())); } this.addSecureUrl(urlPath, configAttributeDefinition); } }
Julian
pd: same post is here http://forum.springframework.org/viewtopic.php?t=5737, buit i changed the topic's category since this is more suitable i guess. Please post here.


Reply With Quote