hivemind-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman" <>
Subject RE: access hibernate session
Date Thu, 14 Oct 2004 01:15:03 GMT
John, there is a WIKI
( page set up to
discuss Hibernate support in Hivemind.  I have posted an example application
) as a comment on the JIRA issue which requests Hibernate support in
Hivemind, which you can download and run.  It might give you some good
ideas.  I'm not saying that my solution is the best solution, but it can get
you started.  I hope the example can help you.  Let me know if you need

-----Original Message-----
From: John Coleman [] 
Sent: Tuesday, October 12, 2004 7:41 PM
Subject: access hibernate session

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:

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

View raw message