hivemind-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Coleman" <>
Subject access hibernate session
Date Tue, 12 Oct 2004 23:41:00 GMT
I want to access HiveMind services in my Tapestry application.

In my engine I put this:-

 protected Object createGlobal(RequestContext context) {
        Global global = (Global) super.createGlobal(context);
        return global;

 public UserService getUserService() {
  if (userService == null) {
   userService = (UserService) ((Global)
  return userService;

I use the engine to instantiate the Global object with the registry:-

 // for services
 public void initResitry(RequestContext context) {
  if (registry == null) {
   registry = HiveMindFilter.getRegistry(context.getRequest());

I am interested in comments on this design. How are others dealing with
their HiveMind service references in Tapestry?

My main question is about how services inside HiveMind will share a
"SessionManager" service, and can I make that service private to classes
inside HiveMind.

I have considered a SessionManager interface but at the moment simply have a
implementation like this:-

public class HibernateSessionManager {

    private static final SessionFactory sessionFactory;

 static {
        // Create the SessionFactory
  try {
       sessionFactory = new
        } catch (Throwable ex) {
         throw new ExceptionInInitializerError(ex);
 // variable to hold a session object for a thread
    public static final ThreadLocal session = new ThreadLocal();

    // obtain the session of the current thread
    public static Session currentSession() throws HibernateException {
     Session s = (Session) session.get();
        // Open a new Session, if this Thread has none yet
        if (s == null) {
            s = sessionFactory.openSession();
        return s;

    // close the session on the current thread
    public static void closeSession() throws HibernateException {
        Session s = (Session) session.get();
        if (s != null) s.close();


I suppose as everything is static I can just use static access, but is that
best practice as that will tie me to an implemenation class! I would rather
create an interface and be get a ref to the implementing class that is
defined in the xml configs.

Is there an example xml to show me this please?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message