GUJ Discussões   :   últimos tópicos   |   categorias   |   GUJ Respostas

Lazy Fetching na View - LazyInitializationException - Hibernate 3.6 + Spring 3.0

Fala pessoal gostaria da ajuda de vocês. Estou fazendo um pequeno projeto com Hibernate e Spring. Estou enfrentando uma LazyInitializationException sempre que tento acessar os atributos Lazy dos objetos no JSP ou no servlet. Eu adotei o filtro OpenSessionInViewFilter mas mesmo assim a exceção é lançada. Eu entendo que de alguma forma a sessão está sendo fechada mas não sei como evitar isso. Abaixo estou postando a exceção, o aplicationContext.xml, o web.xml e algumas classes. Essencialmente são duas entidade com relação Many To One e One To Many com Lazy Fetching.

org.apache.jasper.JasperException: javax.el.ELException: Error reading 'userList' on type com.vh.lab.entities.School_$$_javassist_0
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.vh.lab.servlets.UserServlet.doGet(UserServlet.java:38)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

root cause

javax.el.ELException: Error reading 'userList' on type com.vh.lab.entities.School_$$_javassist_0
	javax.el.BeanELResolver.getValue(BeanELResolver.java:66)
	javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
	org.apache.el.parser.AstValue.getValue(AstValue.java:118)
	org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
	org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
	org.apache.jsp.index_jsp._jspx_meth_c_005fforEach_005f0(index_jsp.java:110)
	org.apache.jsp.index_jsp._jspService(index_jsp.java:82)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.vh.lab.servlets.UserServlet.doGet(UserServlet.java:38)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

root cause

org.hibernate.LazyInitializationException: could not initialize proxy - no Session
	org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167)
	org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)
	org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
	com.vh.lab.entities.School_$$_javassist_0.getUserList(School_$$_javassist_0.java)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
	javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
	org.apache.el.parser.AstValue.getValue(AstValue.java:118)
	org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
	org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
	org.apache.jsp.index_jsp._jspx_meth_c_005fforEach_005f0(index_jsp.java:110)
	org.apache.jsp.index_jsp._jspService(index_jsp.java:82)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.vh.lab.servlets.UserServlet.doGet(UserServlet.java:38)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

applicationContext.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:aop="http://www.springframework.org/schema/aop"
		xmlns:tx="http://www.springframework.org/schema/tx"
		xsi:schemaLocation="http://www.springframework.org/schema/beans
							http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
							http://www.springframework.org/schema/tx
							http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
							http://www.springframework.org/schema/aop
							http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

	<tx:annotation-driven/>
	
	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"/>
	</bean>
	
	<bean id="userService" class="com.vh.lab.service.impl.UserServiceImpl">
		<property name="schoolDao" ref="schoolDao"/>
		<property name="userDao" ref="userDao"/>
	</bean>
	
	<bean id="userDao" class="com.vh.lab.dao.impl.UserDaoImpl">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	<bean id="schoolDao" class="com.vh.lab.dao.impl.SchoolDaoImpl">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	<tx:advice id="txAdvice" transaction-manager="txManager">
		<tx:attributes>
			<tx:method name="get*" propagation="REQUIRES_NEW" read-only="true"/>
			<tx:method name="*"/>
		</tx:attributes>
	</tx:advice>
		
	<aop:config>
		<aop:pointcut id="ServiceOperation" expression="execution(* com.vh.lab.service.impl.*.*(..))"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="ServiceOperation"/>
	</aop:config>
	
	<bean id="dataSource" 
		class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="url">
			<value>jdbc:mysql://localhost/test</value>
		</property>
		<property name="username">
			<value>vh</value>
		</property>
		<property name="password">
			<value>pass</value>
		</property>
		<property name="driverClassName">
			<value>com.mysql.jdbc.Driver</value>
		</property>
		<property name="initialSize">
			<value>5</value>
		</property>
		<property name="maxActive">
			<value>20</value>
		</property>
		<property name="maxIdle">
			<value>5</value>
		</property>
		<property name="poolPreparedStatements">
			<value>true</value>
		</property>
	</bean>

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource">
			<ref local="dataSource" />
		</property>
		<property name="annotatedClasses">
			<list>
				<value>com.vh.lab.entities.User</value>
				<value>com.vh.lab.entities.School</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
				<prop key="show_sql">true</prop>
				<prop key="hibernate.generate_statistics">true</prop>
				<prop key="hibernate.use_sql_comments">true</prop>
				<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
	</bean>
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SpringLab</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

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

<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>classpath:/applicationContext.xml</param-value>
</context-param>


  <listener>
    <listener-class>com.vh.lab.listeners.AppContextListener</listener-class>
  </listener>
  <servlet>
    <description></description>
    <display-name>UserServlet</display-name>
    <servlet-name>UserServlet</servlet-name>
    <servlet-class>com.vh.lab.servlets.UserServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>UserServlet</servlet-name>
    <url-pattern>/user/*</url-pattern>
  </servlet-mapping>
    
<filter>
  	<filter-name>OpenSessionInViewFilter</filter-name>
  	<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
	<init-param>
		<param-name>singleSession</param-name>
		<param-value>true</param-value>
	</init-param>
    <init-param>
	    <param-name>sessionFactoryBeanName</param-name>
    	<param-value>sessionFactory</param-value>
    </init-param>
</filter>
<filter-mapping>
  <filter-name>OpenSessionInViewFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>
<jsp-config>
<taglib>
	<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
	<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
	<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
	<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
</jsp-config>  
</web-app>

Trecho do jsp (index.jsp) – Aqui é lançada a exceção

<c:forEach var="user"  items="${school.userList}">
<c:out value="${user.firstName}"></c:out>
</c:forEach>

Entidades - School.java e User.java


@Data
@Entity
public class School {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	private String Name;
	@OneToMany(mappedBy = "school")
	private List<User> userList;

//getter and setters

	@Transactional
	public List<User> getUserList(){
		return userList;
	}
}

@Data
@Entity
public class User {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	private String firstName;
	@ManyToOne
	private School school;

//getter and setters
}

UserServiceImpl.java


public class UserServiceImpl implements UserService{

	private SchoolDao schoolDao;
	private UserDao userDao;
	
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	public void setSchoolDao(SchoolDao schoolDao) {
		this.schoolDao = schoolDao;
	}

	@Override
	public void addUser() {
		
		School school = new School();
		school.setName("Grupo1");
		schoolDao.save(school);
		
		School school2 = new School();
		school2.setName("Grupo2");
		schoolDao.save(school2);
		
		School school3 = new School();
		school3.setName("Grupo3");
		schoolDao.save(school3);
		
		User user = new User();
		user.setSchool(school2);
		user.setFirstName("vh1");
		userDao.save(user);
		
		User user2 = new User();
		user2.setSchool(school2);
		user2.setFirstName("vh2");
		userDao.save(user2);

	}
	public School getUserFromSchool(){
		School school = schoolDao.load(School.class, new Integer(2));
		return school;
	}
}

Dao - UserDaoImpl.java


public class GenericDao<T> extends HibernateDaoSupport implements Dao<T> {

	@Override
	public List<T> listAll(Class clazz) {
		return getHibernateTemplate().loadAll(clazz);
	}

	@Override
	public T load(Class clazz, Serializable id) {
		return (T) getHibernateTemplate().load(clazz, id);
	}

	@Override
	public void save(T object) {
		getHibernateTemplate().save(object);
	}

}

public class UserDaoImpl extends GenericDao<User> implements UserDao {

	@Override
	public void saveOrUpdate(User user) {
		getHibernateTemplate().saveOrUpdate(user);
	}
	
}

Servlet - UserServlet.java


public class UserServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	       
    public UserServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		UserService userService = (UserService) AppContextListener.ctx.getBean("userService");
		userService.addUser();
		School school = userService.getUserFromSchool();
		request.setAttribute("school", school);
		request.getRequestDispatcher("/index.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}

O problema ocorre quando chamo o servlet e este envia a requisição para o JSP. A aplicação falha ao tentar buscar os atributos do objeto de tipo School. Quem puder ajudar desde já eu agradeço.

Eu não consegui achar nada de arrado no seu código, talvez seja algum problema com aonde a anotação está sendo feita e qual o método que está sendo chamado.
Achei este post no fórum do Spring que é exatamente o problema que você está tendo e diz o seguinte, talvez faça sentido para você (traduzindo):
"“
Troquei isso:
transactionManagedBean.getMyDAO().save(myObject);
por isso:
transactionManagedBean.saveMyObject(myObject);
”"

Eu só acho que o seu método “getUserFromSchool” deveria receber o ID da escola e retornar uma lista de Users, ao invés de retornar uma escola. Ficou meio estranho. Se mudasse para retornar uma lista de Users, não teria problema de lazy initialization…
Espero ter ajudado um pouco.
Abraço.

Muito estranho. Nao consigo ver onde ele pode estar fechado a session com o .close. Talvez o filtro esteja abrindo e mantendo aberta uma sessao diferente da que voce esta usando no dao. Verifique isso ligando o log, e veja se duas sessions diferentes estao sendo abertas (talvez eles nao se conversem ja que voce esta usando o ApplicationContext programaticamente e diretamente, entao o filtro abre uma e seu dao outra).

Tambem debug para verifiar quem invoca o .close da sua session.

Olá Paulo, eu ativei o log e de fato a sessão está sendo fechada pelo HibernateTransactionManager no servlet. O problema é como faço para manter aberta essa sessão até o jsp. O que me parece é que o filtro está fazendo o seu papel e fechando a sessão após renderizar a página, no entanto os lazy loading nos objetos no jsp parecem estar vinculados a sessão do HibernateTransactionManager que ele fechou, ignorando assim a sessão aberta pelo filtro. Alguma luz?

Visola, os nomes dos métodos das Dao’s são apenas para testar, não refletem totalmente a responsabilidade deles. Como o banco inicia vazio, no addUser() por exemplo eu adiciona alguns usuários e escolas para popular o banco. Semelhante ocorre na tentativa de carregar um objeto escola para buscar os usuários de uma escola no método getUserFromSchool, o nome mais aconselhado seria getSchool de fato mas como pertence ao método UserDao por se tratar de um teste, pode parecer realmente estranho.

INFO: Server startup in 4879 ms
13:56:04,934 DEBUG http-8080-1 support.OpenSessionInViewFilter:239 - Using SessionFactory 'sessionFactory' for OpenSessionInViewFilter
13:56:04,939 DEBUG http-8080-1 support.DefaultListableBeanFactory:242 - Returning cached instance of singleton bean 'sessionFactory'
13:56:04,977 DEBUG http-8080-1 support.OpenSessionInViewFilter:181 - Opening single Hibernate Session in OpenSessionInViewFilter
13:56:04,978 DEBUG http-8080-1 hibernate3.SessionFactoryUtils:316 - Opening Hibernate Session
13:56:05,066 DEBUG http-8080-1 support.DefaultListableBeanFactory:242 - Returning cached instance of singleton bean 'userService'
13:56:05,084 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:365 - Creating new transaction with name [com.vh.lab.service.impl.UserServiceImpl.addUser]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
13:56:05,085 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:493 - Opened new Session [org.hibernate.impl.SessionImpl@1f9f0f2] for Hibernate transaction
13:56:05,085 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:504 - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@1f9f0f2]
13:56:05,108 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:569 - Exposing Hibernate transaction as JDBC transaction [jdbc:mysql://localhost/test, UserName=root@localhost, MySQL-AB JDBC Driver]
13:56:05,110 DEBUG http-8080-1 hibernate3.HibernateTemplate:397 - Found thread-bound Session for HibernateTemplate
Hibernate: /* insert com.vh.lab.entities.School */ insert into School (Name) values (?)
13:56:05,191 DEBUG http-8080-1 hibernate3.HibernateTemplate:422 - Not closing pre-bound Hibernate Session after HibernateTemplate
13:56:05,192 DEBUG http-8080-1 hibernate3.HibernateTemplate:397 - Found thread-bound Session for HibernateTemplate
Hibernate: /* insert com.vh.lab.entities.School */ insert into School (Name) values (?)
13:56:05,193 DEBUG http-8080-1 hibernate3.HibernateTemplate:422 - Not closing pre-bound Hibernate Session after HibernateTemplate
13:56:05,193 DEBUG http-8080-1 hibernate3.HibernateTemplate:397 - Found thread-bound Session for HibernateTemplate
Hibernate: /* insert com.vh.lab.entities.School */ insert into School (Name) values (?)
13:56:05,194 DEBUG http-8080-1 hibernate3.HibernateTemplate:422 - Not closing pre-bound Hibernate Session after HibernateTemplate
13:56:05,195 DEBUG http-8080-1 hibernate3.HibernateTemplate:397 - Found thread-bound Session for HibernateTemplate
Hibernate: /* insert com.vh.lab.entities.User */ insert into User (firstName, school_id) values (?, ?)
13:56:05,200 DEBUG http-8080-1 hibernate3.HibernateTemplate:422 - Not closing pre-bound Hibernate Session after HibernateTemplate
13:56:05,200 DEBUG http-8080-1 hibernate3.HibernateTemplate:397 - Found thread-bound Session for HibernateTemplate
Hibernate: /* insert com.vh.lab.entities.User */ insert into User (firstName, school_id) values (?, ?)
13:56:05,202 DEBUG http-8080-1 hibernate3.HibernateTemplate:422 - Not closing pre-bound Hibernate Session after HibernateTemplate
13:56:05,202 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:752 - Initiating transaction commit
13:56:05,202 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:652 - Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@1f9f0f2]
13:56:05,212 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:734 - Closing Hibernate Session [org.hibernate.impl.SessionImpl@1f9f0f2] after transaction
13:56:05,213 DEBUG http-8080-1 hibernate3.SessionFactoryUtils:789 - Closing Hibernate Session
13:56:05,220 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:365 - Creating new transaction with name [com.vh.lab.service.impl.UserServiceImpl.getUserFromSchool]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly
13:56:05,220 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:493 - Opened new Session [org.hibernate.impl.SessionImpl@1bca1c3] for Hibernate transaction
13:56:05,221 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:504 - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@1bca1c3]
13:56:05,222 DEBUG http-8080-1 datasource.DataSourceUtils:153 - Setting JDBC Connection [jdbc:mysql://localhost/test, UserName=root@localhost, MySQL-AB JDBC Driver] read-only
13:56:05,223 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:569 - Exposing Hibernate transaction as JDBC transaction [jdbc:mysql://localhost/test, UserName=root@localhost, MySQL-AB JDBC Driver]
13:56:05,224 DEBUG http-8080-1 hibernate3.HibernateTemplate:397 - Found thread-bound Session for HibernateTemplate
13:56:05,229 DEBUG http-8080-1 hibernate3.HibernateTemplate:422 - Not closing pre-bound Hibernate Session after HibernateTemplate
13:56:05,230 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:752 - Initiating transaction commit
13:56:05,230 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:652 - Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@1bca1c3]
13:56:05,235 DEBUG http-8080-1 datasource.DataSourceUtils:222 - Resetting read-only flag of JDBC Connection [jdbc:mysql://localhost/test, UserName=root@localhost, MySQL-AB JDBC Driver]
13:56:05,235 DEBUG http-8080-1 hibernate3.HibernateTransactionManager:734 - Closing Hibernate Session [org.hibernate.impl.SessionImpl@1bca1c3] after transaction
13:56:05,235 DEBUG http-8080-1 hibernate3.SessionFactoryUtils:789 - Closing Hibernate Session
11/01/2011 13:56:05 org.apache.catalina.core.ApplicationDispatcher invoke
GRAVE: Servlet.service() for servlet jsp threw exception
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
	at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167)
	at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
	at com.vh.lab.entities.School_$$_javassist_0.getUserList(School_$$_javassist_0.java)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
	at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:118)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
	at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
	at org.apache.jsp.index_jsp._jspx_meth_c_005fforEach_005f0(index_jsp.java:110)
	at org.apache.jsp.index_jsp._jspService(index_jsp.java:82)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
	at com.vh.lab.servlets.UserServlet.doGet(UserServlet.java:27)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Unknown Source)
13:56:05,395 DEBUG http-8080-1 support.OpenSessionInViewFilter:207 - Closing single Hibernate Session in OpenSessionInViewFilter
13:56:05,395 DEBUG http-8080-1 hibernate3.SessionFactoryUtils:789 - Closing Hibernate Session
11/01/2011 13:56:05 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet UserServlet threw exception
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
	at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167)
	at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
	at com.vh.lab.entities.School_$$_javassist_0.getUserList(School_$$_javassist_0.java)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
	at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:118)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
	at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
	at org.apache.jsp.index_jsp._jspx_meth_c_005fforEach_005f0(index_jsp.java:110)
	at org.apache.jsp.index_jsp._jspService(index_jsp.java:82)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
	at com.vh.lab.servlets.UserServlet.doGet(UserServlet.java:27)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Unknown Source)

Pelo seu log, o Paulo tinha razão, você (o Spring) está abrindo duas sessões (linhas 8 e 31).
Talvez isso esteja acontecendo pela maneira como você está pegando o contexto da aplicação de dentro do seu servlet.
Você tem dois listeners, um do Spring e outro seu. Dentro do seu servlet você usa o seu listener para pegar o contexto da aplicação.
Mas o filtro do Spring deve usar o contexto do listener do Spring.
Tenta pegar o contexto do Spring diretamente de dentro do seu servlet:

WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
UserService userService = (UserService) ctx.getBean("userService");
...

Muito obrigado Visola e Paulo, realmente o problema foi resolvido. De fato estava criando um objeto do tipo ApplicationContext assim que a aplicação subia.

public void contextInitialized(ServletContextEvent event) {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");
	}

Me corrija se estiver errado… esse contexto é criado quando subo aplicação pelo listener org.springframework.web.context.ContextLoaderListener que declaro no meu web.xml. Ao criar um contexto por conta própria gerei uma exceção ao tentar acessá-lo no servlet/jsp.

Sim, o listener do Spring cria o ApplicationContext para sua aplicação automaticamente a partir do XML dentro do WEB-INF.
Esse outro ApplicationContext que você cria dentro do seu listener, não é necessário.

A exceção estava ocorrendo porque quando o Spring criava seu contexto, o filtro OpenSessionInViewFilter buscava a sessão de um ApplicationContext, enquanto seu Servlet estava buscando em outro ApplicationContext. Quando o seu JSP era executado, a sessão criada pelo Spring continuava aberta, porém, seu objeto foi criado em outra sessão, por isso quando ele tentava carregar a lista dava a exceção, porque a sessão da qual ele foi carregado já não existia mais.

//