Thursday, August 27, 2009

Hibernate session and Wicket filters

I am working on a web application with Spring, Hibernate and Wicket. I need to define Hibernate session filter in web.xml for "open session in view". But I kept getting Hibernate errors when the app started. The fix, as noted in "Wicket in Action", is to define Hibernate session filter ahead of Wicket filter in web.xml.

Here is a complete web.xml as example.

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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"
version="2.4">

<display-name>skills</display-name>

<!-- Hibernate session filter -->
<filter>
<filter-name>hibernateFilter</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>
</filter>

<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!--
There are three means to configure Wickets configuration mode and they
are tested in the order given. 1) A system property:
-Dwicket.configuration 2) servlet specific <init-param> 3) context
specific <context-param> The value might be either "development"
(reloading when templates change) or "deployment". If no configuration
is found, "development" is the default.
-->

<filter>
<filter-name>wicket.skills</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.guident.skills.web.SkillsWicketApplication</param-value>
</init-param>
<init-param>
<param-name>configuration</param-name>
<param-value>development</param-value>
<!--
change "development" to "deployment" for production
<param-value>deployment</param-value>
-->
</init-param>
</filter>

<filter-mapping>
<filter-name>wicket.skills</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


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

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


</web-app>

No comments:

Post a Comment