Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Data Access

Reply
 
Thread Tools Display Modes
  #1  
Old May 19th, 2008, 10:20 AM
sebajb sebajb is offline
Junior Member
 
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
Reply With Quote
  #2  
Old May 19th, 2008, 06:05 PM
josipj josipj is offline
Junior Member
 
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
Reply With Quote
  #3  
Old May 21st, 2008, 03:37 PM
sebajb sebajb is offline
Junior Member
 
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.
Reply With Quote
  #4  
Old May 21st, 2008, 03:59 PM
josipj josipj is offline
Junior Member
 
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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:53 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.