Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

OpenSessionInViewFilter problem

  Asked By: Boell    Date: Mar 06    Category: Java    Views: 1494
  

in a project includes spring,hibernate and struts framework
i want to use OpenSessionInViewFilter approach due to utilize lazy
fetching.
i have added this code snippet in my web.xml file:

<filter>
<filter-name>openSessionInView</filter-name>
<filter-
class>org.springframework.orm.hibernate.support.OpenSessionInViewFilt
er</filter-class>
</filter>

<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>


but unfortunately when i run application server the following stack
error araises:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named 'sessionFactory' is
defined
org.springframework.beans.factory.support.DefaultListableBean
Factory.getBeanDefinition

(DefaultListableBeanFactory.java:352)
org.springframework.beans.factory.support.AbstractBeanFactory
.getMergedBeanDefinition

(AbstractBeanFactory.java:671)
org.springframework.beans.factory.support.AbstractBeanFactory
.getBean

(AbstractBeanFactory.java:198)
org.springframework.beans.factory.support.AbstractBeanFactory
.getBean

(AbstractBeanFactory.java:151)
org.springframework.context.support.AbstractApplicationContex
t.getBean

(AbstractApplicationContext.java:559)
org.springframework.orm.hibernate.support.OpenSessionInViewFi
lter.lookupSessionFactory

(OpenSessionInViewFilter.java:222)
org.springframework.orm.hibernate.support.OpenSessionInViewFi
lter.lookupSessionFactory

(OpenSessionInViewFilter.java:207)
org.springframework.orm.hibernate.support.OpenSessionInViewFi
lter.doFilterInternal

(OpenSessionInViewFilter.java:146)
org.springframework.web.filter.OncePerRequestFilter.doFilter
(OncePerRequestFilter.java:76)


i don't know what the problem is!:(
is there any idea about this problem?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Paul Brooks     Answered On: Mar 06

please post the code  you are using during the open view session filter.

also, what is the scope of your form bean? my gues is that this filter  only works when your actions happen in session scope

 
Answer #2    Answered By: Sheryl Morgan     Answered On: Mar 06

i tried it with forms in session scope but no changed occured and the previous error araised.

about my code: i don't use any special code  i use the following code for getting my objects from DB :


public List getPolicies(){

return getHibernateTemplate().executeFind(
new HibernateCallback()
{
public Object doInHibernate(Session session)
throws HibernateException, SQLException {

Criteria crit = session.createCriteria(Policy.class);
return crit.list();

}

});

}


and after that in my jsp i print objects exist in Policy through its getter method.

i tried another solution for lazy fetching in spring, ie: openSessionInViewInterceptor.
but what wrong goes with this strategy is that session is closed when i want to access any objects in object Policy

 
Didn't find what you were looking for? Find more on OpenSessionInViewFilter problem Or get search suggestion and latest updates.