Announcement Announcement Module
Collapse
No announcement yet.
Problem regarding OpenSessionInViewFilter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem regarding OpenSessionInViewFilter

    Hi,
    I am using hibernate 2.1 with the spring framework. I use the following code in web.xml
    <filter>
    <filter-name>openSessionInViewFilter</filter-name>
    <filter-class>
    org.springframework.orm.hibernate.support.OpenSess ionInViewFilter
    </filter-class>
    <init-param>
    <param-name>sessionFactoryBeanName</param-name>
    <param-value>localSessionFactory</param-value>
    </init-param>
    <init-param>
    <param-name>singleSession</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>openSessionInViewFilter</filter-name>
    <url-pattern>action to forward to</url-pattern>
    </filter-mapping>

    I use hibernateTemplate to execute my queries. When I start my application, there is a session created by the filter and bound to the thread. The hibernate template seems to be creating another session and closes the session which is executing the query. This in turn is causing issues regarding lazy loading as the session does not seem to exist. Please look at the debug messages which show that a different session is created to run the query.

    2005-04-14 10:12:58,038 DEBUG org.springframework.orm.hibernate.support.OpenSess ionInViewFilter - Opening single Hibernate session in OpenSessionInViewFilter
    2005-04-14 10:13:02,711 DEBUG org.springframework.orm.hibernate.SessionFactoryUt ils - Opening Hibernate session
    2005-04-14 10:13:02,711 DEBUG net.sf.hibernate.impl.SessionImpl - opened session
    2005-04-14 10:13:02,711 DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Bound value [org.springframework.orm.hibernate.SessionHolder@9d b94d] for key [net.sf.hibernate.impl.SessionFactoryImpl@29043] to thread [ExecuteThread: '14' for queue: 'weblogic.kernel.Default']
    2005-04-14 10:13:03,758 DEBUG org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'awardDetailServiceImpl'
    2005-04-14 10:13:06,477 DEBUG org.springframework.orm.hibernate.SessionFactoryUt ils - Opening Hibernate session
    2005-04-14 10:13:06,477 DEBUG net.sf.hibernate.impl.SessionImpl - opened session
    2005-04-14 10:13:06,477 DEBUG net.sf.hibernate.impl.SessionImpl - find:

    I want the hibernate template to use the session created by the filter. I also tried forcing it by setting allowCreate to false in the template, but it in turn throws an exception.

    Any help regarding this will be appreciated.

    Sudarshan.

  • #2
    I am seeing that there are 2 application contexts created. Is there any way the I can make the openSessionInViewFilter use the one created by struts?

    Comment

    Working...
    X