Announcement Announcement Module
Collapse
No announcement yet.
Illegal attempt to associate a collection with two open sessions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Illegal attempt to associate a collection with two open sessions

    I've gone through previous posts on this forum, but still cannot resolve this. Maybe I'm just too new to Spring & Hibernate. Please help.
    Stacktrace:
    2011-09-02 09:37:50,188 ERROR BaseAction.saveApplication:1
    82 - Exception occurred while trying to save creditapplication to db.
    CreditApplicationSaveException: org.springframework.orm.hibernate3.HibernateSystem Exception:
    Illegal attempt to associate a collection with two open sessions;
    nested exception is org.hibernate.HibernateException:
    Illegal attempt to associate a collection with two open sessions
    CreditApplicationSaveException: org.springframework.orm.hibernate3.HibernateSystem Exception:
    Illegal attempt to associate a collection with two open sessions;
    nested exception is org.hibernate.HibernateException:
    Illegal attempt to associate a collection with two open sessions
    at CreditApplicationServiceImpl.save(CreditApplicatio nServiceImpl.java:283)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:182)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :149)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:106)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy48.save(Unknown Source)
    at BaseAction.saveApplication(BaseAction.java:172)
    at BusinessInformationAction.save(BusinessInformation Action.java:187)
    at BusinessInformationAction.execute(BusinessInformat ionAction.java:129)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.opensymphony.xwork2.DefaultActionInvocation.in vokeAction(DefaultActionInvocation.java:452)
    at com.opensymphony.xwork2.DefaultActionInvocation.in vokeActionOnly(DefaultActionInvocation.java:291)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:254)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflo wInterceptor.doInte
    rcept(DefaultWorkflowInterceptor.java:176)
    at com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:9 8)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.validator.ValidationInterc eptor.doIntercept(ValidationInterceptor.java:263)
    at org.apache.struts2.interceptor.validation.Annotati onValidationInterce
    ptor.doIntercept(AnnotationValidationInterceptor.j ava:68)
    at com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:9 8)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.ConversionErro rInterceptor.intercept(ConversionErrorInterceptor. java:133)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.ParametersInte rceptor.doIntercept(ParametersInterceptor.java:207 )
    at com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:9 8)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.ParametersInte rceptor.doIntercept(ParametersInterceptor.java:207 )
    at com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:9 8)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.StaticParamete rsInterceptor.intercept(StaticParametersIntercepto r.java:190)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at org.apache.struts2.interceptor.MultiselectIntercep tor.intercept(MultiselectInterceptor.java:75)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at org.apache.struts2.interceptor.CheckboxInterceptor .intercept(CheckboxInterceptor.java:94)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at org.apache.struts2.interceptor.FileUploadIntercept or.intercept(FileUploadInterceptor.java:243)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInt erceptor.intercept(ModelDrivenInterceptor.java:100 )
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.ScopedModelDri venInterceptor.inte
    rcept(ScopedModelDrivenInterceptor.java:141)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at org.apache.struts2.interceptor.debugging.Debugging Interceptor.intercept(DebuggingInterceptor.java:26 7)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.ChainingInterc eptor.intercept(ChainingInterceptor.java:142)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.PrepareInterce ptor.doIntercept(PrepareInterceptor.java:166)
    at com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:9 8)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.I18nIntercepto r.intercept(I18nInterceptor.java:176)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at org.apache.struts2.interceptor.ServletConfigInterc eptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.AliasIntercept or.intercept(AliasInterceptor.java:190)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.interceptor.ExceptionMappi ngInterceptor.intercept(ExceptionMappingIntercepto r.java:187)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at org.apache.struts2.impl.StrutsActionProxy.execute( StrutsActionProxy.java:52)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAc tion(Dispatcher.java:485)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations .executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrep areAndExecuteFilter.doFilter(StrutsPrepareAndExecu teFilter.java:91)
    at weblogic.servlet.internal.FilterChainImpl.doFilter (FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$Ser vletInvocationAction.run(WebAppServletContext.java :3592)
    at weblogic.security.acl.internal.AuthenticatedSubjec t.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(Se curityManager.java:
    121)
    at weblogic.servlet.internal.WebAppServletContext.sec uredExecute(WebAppServletContext.java:2202)
    at weblogic.servlet.internal.WebAppServletContext.exe cute(WebAppServletContext.java:2108)
    at weblogic.servlet.internal.ServletRequestImpl.run(S ervletRequestImpl.java:1432)
    at weblogic.work.ExecuteThread.execute(ExecuteThread. java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java :173)

  • #2
    Here's more info:
    Hibernate config:

    <hibernate-mapping default-cascade="all" default-lazy="false" >
    <class name="CreditApplication" table="CREDITAPPLICATION">
    <id name="applicationId" type="long" column="applicationId">
    <generator class="assigned"/></id>
    <version column="version" name="version" type="integer" unsaved-value="null"/>
    <property name="dateApplicationReceived" type="timestamp" />
    <property name="applicationCompletionDate" type="timestamp" />
    <property name="createdDate" type="timestamp" column="CREATED_DATE" />
    <property name="systemId" type="string" />
    <property name="status" type="string" />
    <component name="Business" class="Business">
    <property name="businessName" type="string" />
    <property name="businessStreetLine1" type="string" />
    <property name="businessStreetLine2" type="string" />
    <property name="businessCity" type="string" />
    <property name="businessState" type="string" />
    <property name="businessZip" type="string" />
    <list name="bankAccounts" table="BUSINESSACCOUNT_REL" cascade="all-delete-orphan">
    <key column="applicationId"/>
    <index column="ACCOUNTSEQUENCE"/>
    <many-to-many class="BankAccount" column="BANKACCOUNTPK"/>
    </list>
    </component>
    <set name="Products" table="APPLICATIONPRODUCT" cascade="all-delete-orphan">
    <key column="applicationId"/>
    <one-to-many class="BaseProduct"/>
    </set>
    <list name="Guarantors" table="GUARANTOR" cascade="all-delete-orphan" >
    <key column="applicationId" />
    <index column="LISTINDEX" />
    <one-to-many class="Guarantor"/>
    </list>
    </class>

    HibernateCreditApplicationDao.java

    public class HibernateCreditApplicationDao extends HibernateDaoSupport
    implements CreditApplicationDao {
    public void save(CreditApplication creditApplication) {
    log.debug("HibernateCreditApplicationDao.save()... ");

    getHibernateTemplate().saveOrUpdate(creditApplicat ion);
    }
    }

    Comment


    • #3
      Please use [ code][/code ] tags when posting code that way it remains readable...

      I suggest google... You are probably managing your relations in the wrong way (either you are (re)setting the collection or are storing it in another object).

      Comment


      • #4
        But the same relationships as before. The same hibernate & spring configurations are used in my struts 1 application.

        Comment


        • #5
          Sorry.. some background... I am migrating from struts 1 to struts 2. I kept everything the same on the hibernate and spring side of things. The only thing that is different is the removal of the validationform data object from struts 1. I am using hibernate 3.2.5.ga with spring 2.5.6 on struts 2.2.1.

          Comment


          • #6
            There are quite some differences between struts 1 and struts 2... If you try to use the object as a form object you will probably run into issues...

            Comment


            • #7
              Can you give examples of the issues I might face? So far I haven't faced any except this spring/hibernate issue. I don't think it's related to me using the Dto objects as form objects. Is it?

              Comment


              • #8
                If you use the hibernate object as a form object and the session remains open, that in combination with an opensessioninview filter might lead to associating a collection with 2 different sessions (when you start to save/update the object). Also if there is going to be some replacement of the list this also might occur.

                Comment


                • #9
                  I'm not using OpenSessionInViewFilter. I get this error even on the first hibernate call to save the application. But there will be subsequent calls to save the application where I will be replacing certain lists. Should I add back the additional data layer? Thanks!

                  Comment

                  Working...
                  X