-->
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: Best design for common "initialization" code
PostPosted: Mon Mar 21, 2005 2:15 pm 
Beginner
Beginner

Joined: Sun May 16, 2004 3:53 pm
Posts: 47
Location: Belo Horizonte, Brazil
Hi.
What are the best designs to have this "initialization" code?
Code:
Datastore ds = Hibernate.createDatastore();
ds.storeClass(User.class);
...
SessionFactory sf = ds.buildSessionFactory(); // or supply a Properties arg
Session session = sf.openSession();


The createDataStore() and storeClass() methods can be called only once for the application.
So I could call it on some kind of filter at the first request of my application for example. Right?

About the buildSessionFactory() method, can I call it only once for the application? And leave the sf obejct there available forever?

The openSession() method I could call before all my façade method just before the database access logic, right?

Thanks.

Hibernate version:anyone

Mapping documents:don`t apply

Code between sessionFactory.openSession() and session.close():don`t apply

Full stack trace of any exception that occurs:don`t apply

Name and version of the database you are using:doesn`t matter really


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 7:48 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Yes, that's one approach. In simple applications I've used the same filter for both the Open-Session-In-View and the initialization, with configuration ocuring during static initialization of the filter.

In practice, configuration can be a pain and for large scale applications an IOC container like Spring or HiveMind can be very helpful in configuring Hibernate.


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.