-->
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.  [ 4 posts ] 
Author Message
 Post subject: Struts/Other clients - Session Beans - Hibernate - MySql
PostPosted: Fri Jan 23, 2004 9:03 am 
Newbie

Joined: Fri Jan 23, 2004 8:09 am
Posts: 3
After reading the Hibernate manual and some forum topics I'm sure that Hibernate is the way to go for our new project! But I still have some questions before I want to start implementing it.

The main problem is that I want to encapsulate the Hibernate specific code so that we can switch to another ORM tool when necessary. Although I already read several posts about this issue I still haven't found the perfect solution.

We have an application using a lot of object with a lot of relations between them. Depending on the requested JSP page (from Struts) I want to select only those objects necessary for building up the page. For example in some cases we need only the Company object, in other cases we need the Company and its list of employees.

One possibility I see is to initialize the Hibernate session in the Struts action and do some inserts/updates/deletes or selects. Commit the transaction and close the session.

But for scalability reasons we want to use a multi-layered architecture. In other words we want the Struts action to talk to a (stateless) session bean that will use hibernate to manage the persistence.

I always try (like most people I guess) to implement the use of a framework like Hibernate in a way that makes it possible to replace it with another framework in the future. This is why I


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 1:20 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This has been discussed, in the end of 2003 and there is no perfect solution.
Basicaly, what I thinks is the best one :
- using DAO encapsulating explicit usage of hibernate especially HSQL queries
- opening and closing hibernate session before the process level usage using AOP or generated wrapper
(- implementing a session abstraction concept as in ORM which delegate to Hibernate)
- you cannot be abstracted of your ORM in the way it solve issues

the Spring Framework is an example of separation pattern while intensive ORM capabilities usage. Juergen will probably detail that ;-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 3:41 am 
Newbie

Joined: Fri Jan 23, 2004 8:09 am
Posts: 3
Thanx for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 1:08 pm 
Senior
Senior

Joined: Wed Aug 27, 2003 6:04 am
Posts: 161
Location: Linz, Austria
emmanuel wrote:
the Spring Framework is an example of separation pattern while intensive ORM capabilities usage. Juergen will probably detail that ;-)


I'm a bit late here, but good point, of course ;-)

Spring provides generic transaction management combined with generic DAO support. You can demarcate your transactions in a generic way in your business facades, without being tied to any particular data access tool. The actual transaction strategy is configurable: for Hibernate, HibernateTransactionManager or JtaTransactionManager would be appropriate.

If your DAOs are coded with Hibernate, the Hibernate Session will automatically get bound to the transaction. So if you rely on lazy loading, you can do that as long as the transaction is active - without dependencies on Hibernate in that transactional business code! On transaction commit, the Session will automatically be closed by Spring's transaction manager.

While Spring provides all of these services for POJOs, either programmatically or declaratively via AOP, it can also be used within EJBs. You simply need to demarcate a transaction with JtaTransactionManager as strategy there, in addition to EJB's CMT: This will automatically participate in the existing JTA transaction, but additionally bind resources like a Hibernate Session for the course of the sub-transaction.

Juergen
http://www.springframework.org
http://www.hibernate.org/110.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.