hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Jakarta-hivemind Wiki] Update of "ImplementingHibernateLongSessions" by Marcus Schulte
Date Mon, 26 Sep 2005 11:23:18 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-hivemind Wiki" for change

The following page has been changed by Marcus Schulte:

New page:
= Implementing the Hibernate long-session-pattern =

Being asked about how to use long hibernate sessions with Hivemind a couple of times on the
Tapestry-Users-List - Here is what I did:

== Overview ==

Basically all one needs to accomplish this is 
   * a persistence service which I called ClientStateStorage. It can be provided with an http
session as the underlying storage mechanism for production. Otherwise it uses a simple Map
for testing.  
   * a service-model extending AbstractServiceModelImpl which works much like the PooledServiceModel,
the differences being firstly, that it comes with a different lifecycle and, secondly that
it doesn't store service-implementations in a pool common to all clients but in the aforementioned

== Implementation ==
Here is the hivemodule.xml making the new service-model available to other modules. As well,
it provides a very simple schema to configure the Hibernate Session Factory.

<?xml version="1.0"?>
<module id="scm.hivemind" version="1.0.0" 
  <contribution configuration-id="hivemind.ServiceModels">
    <service-model class="StatefulServiceModelFactory" 
  <service-point id="ClientStateStorage">
    <invoke-factory model="pooled"> 
		<construct class="ClientStateStorageImpl" />
   <schema id="HibernateSessionFactory">
      <element name="property">
       	a hibernate property       
        <attribute name="name" required="true">
          the property name
        <attribute name="value">
          the value ( as in config.hbm.xml without the leading "hibernate.")
        <conversion class="scm.hivemind.hibernate.HibernateProperty"/>
      <element name="config-xml">
       	the hibernate config.xml File       
        <attribute name="name" required="true">
           the name of the config.xml file
        <conversion class="scm.hivemind.hibernate.HibernateConfigFile"/>


=== Java-Code ===
Here's the Java Code:
==== Client-State-Store ====
   * ClientStateStorage
   * ClientStateStorageImpl
   * StateStorageClearanceListener
   * StatefulHivemindFilter

==== service-model stuff ====
   * StatefulServiceModel
   * StatefulServiceModelFactory
   * StatefulServiceLifecycleListener
==== the hibernate session-factory ====
   * HibernateSessionFactory
   * HibernateProperty
   * HibernateConfigFile

== Usage ==
The following snippet from an applications hivemodule.xml shows how to configure long hibernate
Session which then can be injected into the app-specific services. 
<service-point id="DWKHibernateSession" interface="net.sf.hibernate.Session">
     The hibernate-session itself. 
     <invoke-factory service-id="webkit.awk.DWKSessionFactory" 
  <configuration-point id="DWKSessionFactory" 
  <contribution configuration-id="DWKSessionFactory" >
	  <config-xml name="/scm/extranet/domain/hibernate.cfg.xml"/> 
	  <property name="dialect" value="net.sf.hibernate.dialect.OracleDialect"/>
	  <property name="cache.provider_class" value="net.sf.ehcache.hibernate.Provider"/>
	  <property name="cache.use_query_cache" value="true"/>
  <service-point id="DWKSessionFactory"  
	<invoke-factory model="singleton">
  	<interceptor service-id="hivemind.LoggingInterceptor"/>

In a real web-application you would have to configure the StatefulHivemindFilter for your
controller Servlet.

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

View raw message