-->
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.  [ 7 posts ] 
Author Message
 Post subject: Best Practice Question
PostPosted: Fri Feb 11, 2005 11:00 am 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
Hello all, I have been playing with hibernate for a little bit now and have decided to use it on a new project we are going to develop. In this project we will be hitting a legacy db that is not very well designed. But anyway. We also need to design a middle tier (business objects) that can be accessed via other applications, some not java. We already have some interest from clients to allow them to interact via a Web Services interface. So that will have to be developed. I have a few questions though. In the past I have used Toplink, Oracles ORM. On that application we created the "Sessions" in the business tier and passed them up to the DAO level then closed them after the result was returend(in a finally block) is this the best way to do it in Hibernate? I have seen examples done many ways in the Hibernate in Action book. Also we were considering using ejb's as a business layer. The thought behind this was that we would be able to expose these to other internal applications to use. I was considering using the session facade pattern, any thoughts on this. I appriciate all input. Thank you for the help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 11:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You definitely want the session controlling logic at a layer above the DAOs, and all DAO used within the acheivement of a given use case to use that same Session instance. Just like in TopLink, a Session in Hibernate represents, among other things, a transaction-scoped cache of data.

However, passing Sessions around on all your lower-level components is tedious. Approaches here might be something like constructor-injection or simly passing the Session on each and every method signature. These are generally not recommended approaches.

Generally it is a better approach to store the Session in some contextual manner. The easiest approach for this is using ThreadLocals.


Top
 Profile  
 
 Post subject: Just wanted to add...
PostPosted: Fri Feb 11, 2005 1:30 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
Check this out if you haven't already: http://www.hibernate.org/42.html

I currently use Hibernate in a number of projects. When using SLSB session facades and CMT, we use a variation of the thread local session pattern that allows for a single session to be used in nested transactions (see link).

Quote:
Also we were considering using ejb's as a business layer. The thought behind this was that we would be able to expose these to other internal applications to use.


You don't necessarily need to use EJBs here. I'd carefully weigh all other alternatives prior to throwing your eggs into that basket. EJBs aren't the answer for everything...[/quote]


Top
 Profile  
 
 Post subject: Just wanted to add...
PostPosted: Fri Feb 11, 2005 1:31 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
Check this out if you haven't already: http://www.hibernate.org/42.html

I currently use Hibernate in a number of projects. When using SLSB session facades and CMT, we use a variation of the thread local session pattern that allows for a single session to be used in nested transactions (see link).

Quote:
Also we were considering using ejb's as a business layer. The thought behind this was that we would be able to expose these to other internal applications to use.


You don't necessarily need to use EJBs here. I'd carefully weigh all other alternatives prior to throwing your eggs into that basket. EJBs aren't the answer for everything...[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 1:41 pm 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
Quote:
You don't necessarily need to use EJBs here. I'd carefully weigh all other alternatives prior to throwing your eggs into that basket. EJBs aren't the answer for everything...


What solutions whould you recommend, there is another app, ColdFusion based, that will need to use the business objects to insert and receive data, we dont want this app to know that hibernate is there, it just needs to call our object and get the result or pass data to it. Then we also have an external client that wants to connect via web services. I see so many different approches each saying they are better than the last but no real explanations on why.

Thanks
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 1:44 pm 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
Quote:
You don't necessarily need to use EJBs here. I'd carefully weigh all other alternatives prior to throwing your eggs into that basket. EJBs aren't the answer for everything...


What solutions whould you recommend, there is another app, ColdFusion based, that will need to use the business objects to insert and receive data, we dont want this app to know that hibernate is there, it just needs to call our object and get the result or pass data to it. Then we also have an external client that wants to connect via web services. I see so many different approches each saying they are better than the last but no real explanations on why.

Thanks
Tim


Top
 Profile  
 
 Post subject: When is EJBs appropriate
PostPosted: Fri Feb 11, 2005 1:54 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
I haven't experience with Cold Fusion RPC with Java so I can't really comment on that.

With that said, check out this somewhat dated article I read a long time ago on TSS: http://www.theserverside.com/articles/a ... ppropriate

Lightweight frameworks like SpringFramework certainly can accomodate your needs. Your service layer can be implemented as regular POJOs and you can always migrate to an EJB implementation later should your needs demand it...

HTH,
Roll


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