Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9216165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:21:32+00:00 2026-06-18T02:21:32+00:00

I’m a Spring newbie trying my first app. My hibernate gets closed before the

  • 0

I’m a Spring newbie trying my first app. My hibernate gets closed before the view is rendered and having problems with lazy loaded properties (expected behavior). I’ve added the OpenSessionInViewFilter to my web.xml and caused the following:

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?

Beforehand It was working fine with the default servlet context config I’ve had (can someone tell me why?). So I’ve added the following:

 <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/springapp-servlet.xml
    </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

The new error went away..but still getting a no session exception from hibernate

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.model.Store.categories, could not initialize proxy - no Session

I’ve put a debug message in one of my controllers and it seems that its being initialized 3 times. Maybe I have more than one instance of hibernate session factory bean? My controller methods are marked @Transactional and everything worked until I’ve attempted to leave the session open to make the lazy fields available for the view.

My full web.xml (with the new context addition, worked fine without it before I’ve added the hibernate filter):

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > 
    <display-name>
      Spring
    </display-name>
    <description>
     Spring Test
    </description>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/springapp-servlet.xml
    </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

   <filter>
      <filter-name>hibernateFilter</filter-name>
      <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
      <init-param>
         <param-name>sessionFactoryBeanName</param-name>
         <param-value>sessionFactory</param-value>         
      </init-param>      
   </filter>

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

  <servlet>
    <servlet-name>springapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>



  <servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <error-page>
    <error-code>500</error-code>
    <location>/error/500</location>
  </error-page>
   <error-page>
    <error-code>404</error-code>
    <location>/resources/pages/error.html</location>
  </error-page>



</web-app>

springapp-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
                    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
                    http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
                    http://www.springframework.org/schema/context 
                    http://www.springframework.org/schema/context/spring-context-3.2.xsd
                    http://www.springframework.org/schema/tx
                   http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
                   http://www.springframework.org/schema/aop
                   http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">

    <context:component-scan base-package="com.test.web.controllers,com.test.service.impl" />

    <mvc:annotation-driven />
    <mvc:resources mapping="/resources/**" location="/resources/" /> 

    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/test?zeroDateTimeBehavior=convertToNull"/>
    <property name="username" value="spring"/>
    <property name="password" value="test"/>
  </bean>

  <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource"/>
    <property name="mappingLocations" value="classpath*:com/test/model/hbm/**/*.hbm.xml" />

    <property name="hibernateProperties">
      <value>
        hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
        hibernate.show_sql=true
      </value>
    </property>
  </bean>

 <tx:annotation-driven />
  <bean id="transactionManager"
            class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
  </bean>


    <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath" value="/WEB-INF/templates/"/>
    </bean>
    <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
      <property name="cache" value="true"/>
      <property name="prefix" value=""/>
      <property name="suffix" value=".vm"/>
      <property name="layoutUrl" value="index.vm" />

      <!-- if you want to use the Spring Velocity macros, set this property to true -->
      <property name="exposeSpringMacroHelpers" value="true"/>

    </bean>

     <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

        <!-- one of the properties available; the maximum file size in bytes -->
        <property name="maxUploadSize" value="10000000" />
    </bean>

    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

    <bean id="categoryDAO" class="com.test.dao.hibernate.HibernateCategoryDAO">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="categoryService" class="com.test.service.Categories" scope="singleton">
        <property name="dao" ref="categoryDAO"></property>
    </bean>
    <bean id="storeDAO" class="com.test.dao.hibernate.HibernateStoreDAO">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="storeService" class="com.test.service.Stores" scope="singleton">
        <property name="dao" ref="storeDAO"></property>
        <property name="categoryDao" ref="categoryDAO"></property>

    </bean>

</beans>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:21:35+00:00Added an answer on June 18, 2026 at 2:21 am

    My controllers where initialized twice, the same config was used by the root ApplicationContext and by the FrameworkServlet. I’ve had two contexts initialized. I’ve created a config for the root context named springapp.xml and moved all my middle tier configuration there and left my web tier configuration in springapp-servlet.xml

    My web.xml now looks like this and everything works fine:

          <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                    /WEB-INF/springapp.xml
            </param-value>
            </context-param>
    
         <listener>
                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
            </listener>
    
    <filter>
          <filter-name>hibernateFilter</filter-name>
          <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
          <init-param>
             <param-name>sessionFactoryBeanName</param-name>
             <param-value>sessionFactory</param-value>         
          </init-param>      
       </filter>
    
       <filter-mapping>
         <filter-name>hibernateFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
       </filter-mapping> 
    
        <servlet>
            <servlet-name>springapp</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                    <param-name>contextConfigLocation</param-name>
                    <param-value>/WEB-INF/springapp-servlet.xml</param-value>
            </init-param>
    
            <load-on-startup>1</load-on-startup>
          </servlet>
    
    
    
          <servlet-mapping>
            <servlet-name>springapp</servlet-name>
            <url-pattern>/</url-pattern>
          </servlet-mapping>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.