|
#1
|
|||
|
|||
|
I am trying to use the OpenSessionInViewFilter , but I am not entirely confortable with the examples i've found online and I have not managed to get it to work yet .
I am using Tapestry for the presentation layer , and at times , i'm returning data objects from hibernate that have been lazily initialised . The Tapestry code will call some of the lazy values , and I'm getting session closed excecptions . I have read about the OpenSessionInViewFilter on this forum , since it seems to be a common solution for my question ( allthogh everyone else uses Struts ) . From what I gathered it looks like i need to add the following to my web.xml : Code:
<filter> <filter-name>hibernateFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>/app</url-pattern> </filter-mapping> Thanks |
|
#2
|
|||
|
|||
|
I use
Code:
Hibernate.initialize(object); regards, Juergen |
|
#3
|
|||
|
|||
|
where do you have that code . I'm affraid i'm using Tapestry which uses ognl , which is something similar to the JSP EL language . most of my time i get objects like this and theese would cause problems .
I need something that doesn't require me writting code in the presentation layer if possible is that possible ? |
|
#4
|
|||
|
|||
|
You have to write it there where the transaction is fired for getting the objects...
In our application we make the transaction binding everytime a Manager is called. After the query is running I call the Hibernate.initialize(object) |
|
#5
|
||||
|
||||
|
You can try this one:
Quote:
__________________
Costin Leau SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source" http://twitter.com/costinl Please use [ c o d e ] [ / c o d e ] tags |
|
#6
|
|||
|
|||
|
thanks guys , open filter worked just great , it looks like i kept getting an error due to some bad code in my presentation layer ( this was a test app and i was beeing a bit lazy ) :
transactionManagedBean.getMyDAO().save(myObject); had to change this to transactionManagedBean.saveMyObject(myObject); IT's odd however that i was getting no error before cocnfiguring the filter . . . |
|
#7
|
|||
|
|||
|
Hello,
I'd like to use the OpenSessionInViewFilter with my SpringApp. I searched the forums/docs and did not find a clear documentation/wiki (in fact the majority of the posts were about problems encountered while trying to implement the filter ).Do you have links to a post/documentation where this mechanism is well explained? Thank you, Cristian. |
|
#8
|
|||
|
|||
|
I've got this issue and I've declared opensessioninviewfilter in my web.xml file as mentioned above. But the problem still exist.
Here's my web.xml file: Code:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/my-servlet.xml</param-value>
</context-param>
<filter>
<filter-name>encoding-filter</filter-name>
<filter-class>org.eon.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<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>encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value/>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/pages/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/pages/error.jsp</location>
</error-page>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
__________________
Let's care our nature! |
|
#9
|
|||
|
|||
|
Hello, I have the same one problem, my web.xml is:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <!-- Parameters to load Spring configuration --> <context-param> <param-name>contextConfigLocation</param-name> <!-- Se elimina la referencia a comun-web-context a la espera de que se incorpore la parte comun --> <!-- param-value>classpath*:comun-web-context.xml,classpath*:sgeser-web-context.xml</param-value--> <param-value>classpath*:sgma-web-context.xml</param-value> </context-param> <!-- Parameters to load Tiles configuration --> <context-param> <param-name>org.apache.tiles.impl.BasicTilesContainer.DEF INITIONS_CONFIG</param-name> <param-value>/WEB-INF/sgma-tiles.xml,/org/apache/tiles/classpath-defs.xml</param-value> </context-param> <!-- Filtro para Autenticacion de Usuario --> <!-- <filter> <filter-name>ControlAcceso</filter-name> <filter-class>es.aena.sgcomun.base.web.struts2.autenticaci on.NtlmHttpFilter</filter-class> <init-param> <param-name>jcifs.netbios.wins</param-name> <param-value>10.72.101.1</param-value> </init-param> <init-param> <param-name>jcifs.smb.client.domain</param-name> <param-value>indra</param-value> </init-param> </filter> --> <!-- Filtro auxiliar para las peticiones POST --> <!-- <filter> <filter-name>ControlAccesoPost</filter-name> <filter-class>es.aena.sgcomun.base.web.struts2.autenticaci on.NtlmHttpPostFilter</filter-class> </filter> --> <!-- Filter to activate struts --> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <!-- Filtro para todas las peticiones HTTP --> <!-- <filter-mapping> <filter-name>ControlAcceso</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> --> <!-- Filtro para todas las peticiones HTTP (peticiones post)--> <!-- <filter-mapping> <filter-name>ControlAccesoPost</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> --> <!-- Filter mappings --> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Filtro para el problema con el lazy --> <filter> <filter-name>hibernateFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.O penSessionInViewFilter</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>HBSessionFactory</param-value> </init-param> </filter> <!-- Listener for Struts 2 and Spring dependency injection --> <listener> <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class> </listener> <!-- Listener configuration for Tiles 2, by default takes /WEB-INF/tiles.xml as config file --> <listener> <listener-class>org.apache.struts2.tiles.StrutsTilesListener </listener-class> </listener> <servlet> <servlet-name>InitServlet</servlet-name> <servlet-class>es.aena.sgma.init.servlet.InitServlet</servlet-class> <load-on-startup>10</load-on-startup> </servlet> <welcome-file-list> <welcome-file>/jsp/index.jsp</welcome-file> </welcome-file-list> </web-app> Should I change another thing? I am using struts2, spring and tiles. Thanks very much, and regards |
|
#10
|
|||
|
|||
|
The solution from Costin (see above) works fine, just add a filter-mapping:
Code:
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|