-->
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: Hibernate and DAO Pattern
PostPosted: Thu Oct 23, 2003 4:12 am 
Beginner
Beginner

Joined: Thu Oct 02, 2003 8:02 am
Posts: 45
Fisrt, I wonder if it is possible to use hibernate with the DAO Pattern.
Second, I use servlets as client. Does servlets must directly use DAO objects that encapsulate RDB's access or must i use a layer between servlet and DAO that will act as Business layer.

I notice that i don't want to use EJB.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 4:13 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate is not restricted to a particular architecture. Use it in whatever way you like, but understand SessionFactory, Session and Transaction first.[/quote]

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
must i use a layer between servlet and DAO that will act as Business layer

Not really related to Hibernate, but unless the requirements for your app have extremely modest and straight-forward logic I would highly recommend a business-logic abstraction. There are many ways to implement such a beast such as the Command, Transaction Script, and Service Layer patterns to name a few.

Hibernate would tie pretty nicely with all of those approaches.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 5:03 am 
Newbie

Joined: Fri Oct 03, 2003 6:53 am
Posts: 7
We have been using Hibernate in all of our application DAOs.

A SessionFactory instance for the whole application is created when Hibernate configuration is loaded.

Then, every DAO method that needs to perform a database operation opens a Session from that SessionFactory and closes it when finished.

This is how we have done it, although I'm not sure if this is the best and/or right way to do it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 10:31 pm 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
check out this discussion:http://forum.hibernate.org/viewtopic.php?t=925108

_________________
Mauricio Hern


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 9:01 am 
Newbie

Joined: Thu Sep 25, 2003 7:21 pm
Posts: 17
le_sharingan wrote:
Then, every DAO method that needs to perform a database operation opens a Session from that SessionFactory and closes it when finished.
This is how we have done it.


bt do your dao's contain business logic


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 9:37 am 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
le_sharingan wrote:

Then, every DAO method that needs to perform a database operation opens a Session from that SessionFactory and closes it when finished.



If you do this, you will get OSUser hibernate provider, which
scales ( or at least used to scale ) really poor...

"open session in view" gives you more performance
- in web application you can outsource session management into
request filter.

And another problem with is is lazy loading of collections....

However, if your session lives longer ( and used by several DAOs )
you will have to ensure that stale session ( every session where error happened ) is discarded safely.

Anyway it's kind of tricky...

At the moment I prefer "lifecycle" session from nanocontainer
( well, I use nanocontainer in my app ) , and struggle to make
hibernate session/transaction constructor-injectable.

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


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.