Results 1 to 6 of 6

Thread: Open Session in View Filter Spring Hibernate Struts

  1. #1
    Join Date
    Jun 2005
    Posts
    5

    Default Open Session in View Filter Spring Hibernate Struts

    I am using OpensessionInViewFilter for hibernate 3 "org.springframework.orm.hibernate3.support.OpenSe ssionInViewFilter" and I keep getting the lazy initialization error.

    Here is the filter configuration in web.xml:
    <filter>
    <filter-name>openSessionInViewFilter</filter-name>
    <filter-class>
    org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter
    </filter-class>
    <init-param>
    <param-name>singleSession</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>

    <filter-mapping>
    <filter-name>openSessionInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>


    Here is the hibernate properties in the sessionFactory configuration:
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.SybaseDialect
    </prop>
    <prop key="show_sql">true</prop>
    <prop key="hibernate.cache.use_second_level_cache">
    false
    </prop>
    </props>
    </property>

    I am using declared transaction management and am unsure if this should matter or not.

    I am also using struts and accessing the spring bean through struts. Note that I am not using spring through the struts plugin, but rather through the org.springframework.web.struts.DelegatingActionPro xy.

    I would love some help. It sounds like this should work.
    Is there a standard way to configure

  2. #2
    Join Date
    May 2008
    Posts
    10

    Default

    Hi,

    I'm new to spring but i got my openSessionInViewFilter working.

    What i did is adding the following to my web.xml:
    <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>
    org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter
    </filter-class>

    </filter>

    <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>ERROR</dispatcher>
    </filter-mapping>

    This is a part from my applicationContext.xml file:
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="mappingResources">
    <list>
    <value>rsswebclient/domain/Item.hbm.xml</value>
    <value>rsswebclient/domain/Channel.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>
    <prop key="hibernate.show_sql">false</prop>
    </props>
    </property>
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    </bean>

    There must by a sessionFactory bean present in the applicationContext.xml or you will get "No bean named 'sessionFactory'" error.

    Hope it helps.

    Kind Regards,

    Josip

  3. #3
    Join Date
    Jun 2005
    Posts
    5

    Default Hi josipj,

    I have done exactly as you said and I believe the configuration is correct. My problem might in the fact that I am using hibernate through annotations instead of the usual .hbm.xml files.

    Is there anything special happening with annotations and spring. Do I need to use the @Transaction in the Pojo?

    Anyhelp would be appreciated.

  4. #4
    Join Date
    May 2008
    Posts
    10

    Default

    I'm not using annotations. Maybe it has something to do with it. Could you post the logging.

  5. #5
    Join Date
    Oct 2012
    Location
    Neuss, NRW, Germany
    Posts
    1

    Default

    In order to use annotations please insert in applicationContext.xml not "LocalSessionFactoryBean", but:

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">

  6. #6
    Join Date
    Sep 2012
    Posts
    1

    Default

    Thank you so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •