-->
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 Static
PostPosted: Mon Oct 06, 2003 3:37 pm 
Beginner
Beginner

Joined: Tue Sep 09, 2003 5:28 pm
Posts: 33
Location: Cincinnati, OH
Hi there,

When we create a SessionFactory to get session, we used to do this:

Code:
public class HibernateSessionFactory{
    private static SessionFactory sf = null;
    public static synchronized Session get Session() throws HibernateExceptuion{
        Configuration conf = null;
        if (sf == null) {
            conf = new Configuration().addClass(...);
            sf = conf.buildSessionFactory();

        }
       
        return sf.openSession();
}



Does anyone know why we are using Static function, and variable here?

I thought maybe we only initialize SessionFactory once, but I am not really sure, please help me!

Thanks all a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 3:43 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum
The code says

If I'm not initialized (static sf==null), then I init me. Otherwise I just open a new session from the same session fatory.

So yes, a static method is used for single init.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 3:40 pm 
Beginner
Beginner

Joined: Tue Sep 09, 2003 5:28 pm
Posts: 33
Location: Cincinnati, OH
Thanks for the reply.


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.