public static void doSessionTxWork( Work work ) {
    	SessionFactory factory = getSessionFactory();
    	
    	// Non-managed environment idiom with getCurrentSession()
    	try {
    	    factory.getCurrentSession().beginTransaction();

    	    // do some work
    	    work.work(factory.getCurrentSession());

    	    factory.getCurrentSession().getTransaction().commit();
    	}
    	catch (RuntimeException e) {
    	    Transaction tx = factory.getCurrentSession().getTransaction();
    	    // I added this safeguard to example hibernate code, but I'm not sure it's needed.
    	    if( tx != null ) {
    	    	tx.rollback();
    	    }

    	    logger.error("Caught an exception doing work", e);

    	    throw e; // or display error message
    	}
    }