-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: OpenSessionInViewInterceptor and hibernate L.I.E
PostPosted: Mon Apr 21, 2008 3:42 pm 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

3.2.5

Mapping files
Code:
        <set name="userGroups"
             inverse="true"
             access="field">
          <key column="user_id"/>
          <one-to-many class="UserGroup"/>
        </set>


UserGroup.hbm.xml
Code:
       <class name="UserGroup" table="user_group" mutable="false">
      <composite-id name="id" class="UserGroup$Id">
        <key-property name="userId"  column="user_id"/>
        <key-property name="groupId" column="group_id"/>
      </composite-id>
       <many-to-one
           name="user"
           column="user_id"
           not-null="true"
           insert="false"
           update="false"
           access="field"/>
       <many-to-one
           name="group"
           column="group_id"
           not-null="true"
           insert="false"
           update="false"
           access="field"/>
  </class>




Code between sessionFactory.openSession() and session.close():
I follow my stack trace and found the error to be here.
Code:
@Override
    public GrantedAuthority[] getAuthorities()
    {
        Collection<Group> authorities = new HashSet<Group>();
        for (UserGroup userGroup : getUserGroups())
        {
            authorities.add(userGroup.getGroup());
        }
        return authorities.toArray(new GrantedAuthority[0]);
    }

Full stack trace of any exception that occurs:
Code:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: myproject.util.security.domain.User.userGroups, no session or session was closed
   org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
   org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
   org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
   org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:163)
   myproject.util.security.domain.User.getAuthorities(User.java:160)
   org.springframework.security.providers.dao.AbstractUserDetailsAuthenticationProvider.createSuccessAuthentication(AbstractUserDetailsAuthenticationProvider.java:183)
   org.springframework.security.providers.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:162)
   org.springframework.security.providers.ProviderManager.doAuthentication(ProviderManager.java:195)
   org.springframework.security.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:46)
   org.springframework.security.ui.webapp.AuthenticationProcessingFilter.attemptAuthentication(AuthenticationProcessingFilter.java:81)
   org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:249)
   org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
   org.springframework.security.config.OrderedFilterBeanDefinitionDecorator$OrderedFilterDecorator.doFilter(OrderedFilterBeanDefinitionDecorator.java:93)
   org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
   org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:87)
   org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
   org.springframework.security.config.OrderedFilterBeanDefinitionDecorator$OrderedFilterDecorator.doFilter(OrderedFilterBeanDefinitionDecorator.java:93)
   org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
   org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:229)
   org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
   org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
   org.springframework.security.concurrent.ConcurrentSessionFilter.doFilterHttp(ConcurrentSessionFilter.java:97)
   org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
   org.springframework.security.config.OrderedFilterBeanDefinitionDecorator$OrderedFilterDecorator.doFilter(OrderedFilterBeanDefinitionDecorator.java:93)
   org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
   org.springframework.security.securechannel.ChannelProcessingFilter.doFilterHttp(ChannelProcessingFilter.java:116)
   org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
   org.springframework.security.config.OrderedFilterBeanDefinitionDecorator$OrderedFilterDecorator.doFilter(OrderedFilterBeanDefinitionDecorator.java:93)
   org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
   org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:174)
   org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:183)
   org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:138)
c

oracle 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Thanks for the help.


Last edited by cablepuff on Mon Aug 18, 2008 9:54 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 21, 2008 4:46 pm 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
here is the spring-servlet.xml

Code:
<bean id="securitySessionInViewInterceptor"
        class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
        <property name="sessionFactory">
            <ref bean="exampleSessionFactory"/>
        </property>
        <property name="flushModeName" value="FLUSH_AUTO"/>
    </bean>


<!--  url mapping  -->
    <bean id="simpleUrlMapping"
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="interceptors">
            <list>
                <ref bean="securitySessionInViewInterceptor" />
            </list>
        </property>
        <property name="alwaysUseFullPath">
            <value>false</value>
        </property>
        <property name="mappings">
            <props>
                <prop key="/index.htm">welcomeController</prop>
                <prop key="/group.htm">groupController</prop>
                <prop key="/application.htm">applicationController</prop>
                <prop key="${loginFormUrl}">loginController</prop>
                <prop key="${authenticationFailureUrl}">loginErrorController</prop>
                <prop key="${logoutUrl}">logoutController</prop>
                <prop key="${accessDeniedUrl}">accessdeniedController</prop>
                <prop key="${sessionExpireUrl}">sessionExceededController</prop>
                <prop key="${defaultUrl}">generalController</prop>
            </props>
        </property>
    </bean>



Top
 Profile  
 
 Post subject:
PostPosted: Sun May 11, 2008 2:43 am 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
btw i am using this with spring

and i have OpenSessionInviewInterceptor wired in.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 6:39 pm 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
bump an old topic to see if their is any help.

Alternative question, how would i map getAuthorities to a formula instead of retrieving hte object inside.

Like getAuthority would get the groups which are authorities (since group implements authorities).


The class is User, Group, UserGroup.

I made my implementationa lot like the style in java persistance with hibernate in the section [Join table with additional column]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.