-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: "Open Session in View" Problem
PostPosted: Fri Dec 12, 2003 7:22 am 
Newbie

Joined: Sun Nov 30, 2003 4:46 am
Posts: 17
Hi,

Im using a Struts application in which I have a layered architecture consisting of View (JSP), Control (Action classes), Service Layer (business objects), Domain Model (Domain objects) and a DAO layer.

Im using the business objects, Managers actually, in Action classes.
These managers communicate with the DAO classes by passing Domain objects to and from. The DAO classes internally use Hibernate to perform all the Database operations.

I want to use one Session per web browser request. If I use "Open Session in View" pattern to achieve this, then I'll have to pass the Session object to DAO layer from View to Action to Business objects and then to DAO.

My design requirements are that I want to make all these layers independent of any persistence framework. My DAO impolementation classes using Hibernate are one particular implementation of my DAO interfaces.

Im quite confused and stuck up on how to achieve this independence, but also have to make use of only one Session instance for the entire request

Thanx in advance for any suggestions and tips


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2003 7:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Look at the ThreadLocal-Session pattern at http://www.hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2003 11:01 am 
Senior
Senior

Joined: Wed Aug 27, 2003 6:04 am
Posts: 161
Location: Linz, Austria
Have a look at the Spring Framework's support for resource and transaction management. It is exactly intended for scenarios like yours, providing means for complete abstraction from the actual data access strategy. The article at http://www.hibernate.org/110.html discusses the relevant parts of Spring.

In a Spring-managed application, generic transactions are typically defined for service layer methods, getting automatically propagated to DAOs through the use of ThreadLocals under the covers. Hibernate Sessions are associated with those transactions through the use of the HibernateTransactionManager implementation, without the service layer code being aware of working with Hibernate.

In the upcoming release 1.0 M4, we introduce an OpenSessionInViewFilter to allow for using the "Open Session in View" pattern with Spring-managed transactions. We still recommend to close resources like Sessions before attempting to render a view, but we now offer the choice to keep the Session open until rendering completion.

Note that despite the fact that Spring provides its own web MVC framework, it can serve as middle tier backbone for other web MVC frameworks, or in fact any kind of application. We have numerous people combining Spring with the likes of Struts, WebWork2, and Tapestry; such integration is straightforward.

Juergen
(Spring Framework developer)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.