-->
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.  [ 2 posts ] 
Author Message
 Post subject: Performance Question
PostPosted: Fri Jun 04, 2004 10:36 am 
Beginner
Beginner

Joined: Thu Oct 09, 2003 11:41 am
Posts: 39
Location: Paris, France
Hello,

I have functions in a class that need to call Hibernate as part of their job. So far, what I'm doing is as follows:

Code:
public void myFunction()
        throws MyExceptionClass
{       
       Session session = null;
        try
        {
            // sessionFactory is stored as a private variable
            session = sessionFactory.openSession();

            // doing other stuff: updates, selects, etc.

         }
            session.flush();
            session.close();
        }
        catch (HibernateException e)
        {
            throw new MyExceptionClass(e.getMessage(), activeUser);
        }
}


My questions are:

1. What is the overhead of opening up the session on every function call, flushing it, and closing?
2. Does it make sense to store sessionFactory elsewhere? Should it be in the context somewhere, accessible to all connections? Any pitfalls with this?
3. If the above solution is not optimal, what would be a better way of doing this?

Thanks very much.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 10:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
my opinion:

Quote:
1. What is the overhead of opening up the session on every function call, flushing it, and closing?
2. Does it make sense to store sessionFactory elsewhere? Should it be in the context somewhere, accessible to all connections? Any pitfalls with this?
3. If the above solution is not optimal, what would be a better way of doing this?


1- if you are flushMode = auto (by default), you should consider not manullay flush it, if you have a "commit" function, to be 100% secure you can call session.flush() and then commit
2- the best for a webApp is to use threadLocal Pattern (search open session in view on site) it's the simpliest way to manage hibernate session (and maybe sessionFactory) for such apps
3- see previous point.

Creating a sessionFactory = very expensive
Obtaining a session from a sessionFactory = not expensive
Flushing a session = can be very expensive if you call it every millisecond...[/quote]

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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