-->
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: Session per Conversation DAO Pattern
PostPosted: Mon Jul 17, 2006 6:37 pm 
Newbie

Joined: Fri Jun 09, 2006 8:03 am
Posts: 12
Hibernate version: 3.2

I am trying to make an application that loads an Object using standard HQL. Then it will go through a process of modifing the object, and finally save the object back into the database.

My problem is that I need to have a large amount of data accessed from the database right at the beging of the application, as well as large objects with associations accessed later.

Currently I use a standard DAO pattern with a session opening each time I want to get an object, get the object, then close the session. This, however forces me to use a lazy="false" on most of the associations. I tried to optimize but it had little effect. I am still generating lots of SQL right away.

So, I thought about making a long session. This way I can use lazy initialization to my advantage and only probe the database when I need too. However, there is no really documented way to do this outside of a servlet. I also can't use spring or AspectJ to do AOP on the issue.

Therefore, I need someone to help and point me in the right direction. Assuming, of course that this long conversation approach is the right one...Thanks for any feedback and help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 10:40 am 
Beginner
Beginner

Joined: Wed Jun 21, 2006 10:08 am
Posts: 26
Session per Conversation pattern:

http://www.hibernate.org/42.html#A9

Also, do look through their CaveatEmptor example code. It demonstrates many key features and good guidlines on how to do things.

I have also found that passing a session into the DAO and then you explicitly closing the session later is useful (if only working on 1 object with lazy collections). If there are multiple objects that need to be rolledback on a exception, the session per conversation logic is good for you.

-Please rate me if you found this helpful

_________________
- Jonathan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 9:52 pm 
Newbie

Joined: Fri Jun 09, 2006 8:03 am
Posts: 12
Alright, well this DAO pattern is fine and so is the link you posted. However, I have additional problems. My application is not a web application. I don't have jndi to lookup a factory, and I don't want to use a session per transaction.

So how do i make a current session context that has a long running session but short transactions, without the use of a servlet.


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.