-->
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: using hibernate in a layered fashion..
PostPosted: Thu Oct 23, 2003 5:39 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
this is what I was thinking of doing, in a web-enviroment

using threadlocal to hold the web request's session, one session per web request.

having a UserManager class, this does work with hibernate so ill have a
User UserManager.getUser(String userId) throws HibernateException
all it does is use session.load

and then in my action classes use it like:

executeAction() {
try {
// get session from threadlocal (session already created in a filter)
// start transaction
User user = UserManager.getUser(userId);
// do work with user and other "Manager" classes
// commit transaction
} catch(HibernateException e) {
// rollback the transaction
// a massive failure occured, we're screwed.. show user a "Fatal" error page if we get here..
}
}

theres a few problems here though, what if for some reason I need to use some other persistence mechanism, i wont be able to use this action anymore,
how would I go about generalizing the UserManager to be persistance store agnostic yet be able to use transactions?

im a little confused as to how to do this..
I could have UserManager throw a ManaberException that wraps HibernateExceptions but I would still need to use the hibernate sessions in the action class so I wont be able to use the actions without hibernate.. do not know, someone please advise!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 11:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
yet be able to use transactions?

Sounds like a job for JTA. Hibernate supports JTA transactions.

Definitely try to isolate persistence calls to a single layer rather than spanning multiple layers; this is true whatever your persistence mechanism happens to be. The DAO pattern is just what you are looking for, I think.

You might want to check out the Spring Framework which has really nice support for tying DAO and transactions usage together in a configurable way.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 9:44 am 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
so JTA is what I need to look into, I just noticed that there was a new Spring released, M2, ill have to take a look at that too.


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.