Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring, Hibernate Lazy Loading, sessionFactory, and OpenSessionInViewFilter
    text
    copied!<p>I am using Hibernate's lazy loading, and am getting sessionFactory missing exception, even after I have defined a filter in web.xml to use OpenSessionInViewFilter</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt; &lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/spring/root-context.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- Processes application requests --&gt; &lt;servlet&gt; &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;filter&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &lt;filter-class&gt; org.springframework.orm.hibernate3.support.OpenSessionInViewFilter &lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;/web-app&gt; </code></pre> <p>My servlet-context.xml has following session and transaction manager definitions:</p> <pre><code>&lt;beans:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;beans:property name="dataSource" ref="dataSource"/&gt; &lt;beans:property name="hibernateProperties"&gt; &lt;beans:props&gt; &lt;beans:prop key="hibernate.dialect"&gt;${connection.dialect}&lt;/beans:prop&gt; &lt;beans:prop key="hibernate.show_sql"&gt;true&lt;/beans:prop&gt; &lt;/beans:props&gt; &lt;/beans:property&gt; &lt;beans:property name="annotatedClasses"&gt; &lt;beans:list&gt; &lt;beans:value&gt;example.EntityA&lt;/beans:value&gt; &lt;beans:value&gt;example.EntityB&lt;/beans:value&gt; &lt;/beans:list&gt; &lt;/beans:property&gt; &lt;/beans:bean&gt; &lt;beans:bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;beans:property name="sessionFactory" ref="sessionFactory"/&gt; &lt;/beans:bean&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt; </code></pre> <p>I still get the following exception:</p> <pre><code>org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined </code></pre> <p>I have tried defining a sessionFactoryBeanName attribute but results don't change. What am I doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload