-
May 19th, 2008, 09:20 AM
#1
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
-
May 19th, 2008, 05:05 PM
#2
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
-
May 21st, 2008, 02:37 PM
#3
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.
-
May 21st, 2008, 02:59 PM
#4
I'm not using annotations. Maybe it has something to do with it. Could you post the logging.
-
Oct 9th, 2012, 05:59 AM
#5
In order to use annotations please insert in applicationContext.xml not "LocalSessionFactoryBean", but:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
-
Oct 17th, 2012, 09:14 AM
#6
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
-
Forum Rules