|
Free GigaSpaces Distributed Cache for Hibernate UsersTo get a free distributed cache for your Hibernate database integration, all you need to do is replace your existing Hibernate cache provider, typically EhCache, with the free GigaSpaces Community Edition, in 6 easy steps. NOTE: GigaSpaces fully supports the Spring Framework, and can be plugged in very easily without changing your existing code. For more detailed information, see GigaSpaces for Hibernate ORM Users in the GigaSpaces Wiki Online Help.
1. Download the GigaSpaces Community EditionGigaSpaces Community Edition is a fully-functional version of GigaSpaces which permits unlimited clients but only one server node.
NOTE: If you need more than one server node, download and evaluate GigaSpaces eXtreme Application Platform or XAP - Enterprise Data Grid. 2. Install GigaSpacesIf you need help, refer to the GigaSpaces installation instructions. 3. Switch Your Hibernate Cache Provider to GigaSpacesThis procedure is different if you are managing your Hibernate configuration using Spring (refer to the Spring documentation, ORM Data Access, section 12.2.2), or directly using hibernate.properties or hibernate.cfg.xml. Please read the relevant section below. Spring ConfigurationEdit your SessionFactory Setup. This is the section inside your Spring Application Context File that controls the relevant Hibernate configuration (refer to the Spring documentation, ORM Data Access, section 12.2.2). Add or modify the following properties under <property name="hibernateProperties">:
<prop key="hibernate.cache.provider_class">
org.openspaces.hibernate.cache.SimpleMapCacheProvider</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="gigaspace.hibernate.cache.url">/./space</prop> Direct Configuration using hibernate.propertiesEdit your hibernate.properties file. Add or modify the following properties in the Second-Level Cache section:
hibernate.cache.provider_class org.openspaces.hibernate.cache.SimpleMapCacheProvider
hibernate.cache.use_second_level_cache true
gigaspace.hibernate.cache.url /./space Direct Configuration using hibernate.cfg.xmlEdit your hibernate.cfg.xml file. Add or modify the following properties under <session-factory>:
<property name="hibernate.cache.provider_class">
org.openspaces.hibernate.cache.SimpleMapCacheProvider</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="gigaspace.hibernate.cache.url">/./space</property> 4. Set Cache Usage in Mapping Resource FileSet or add cache usage (the cache concurrency strategy) in your mapping resource file (*.hbm.xml files) to read-only, read-write or nonstrict-read-write:
<class name="your.class.name" table="YourTableName">
<cache usage="nonstrict-read-write"/>
Alternatively, use the <class-cache> and <collection-cache> elements in your hibernate configuration file. 5. Add Required JARs to Your ApplicationMake sure you include the following GigaSpaces JARs in your application classpath: <GigaSpaces Root>\lib\JSpaces.jar; <GigaSpaces Root>\lib\ServiceGrid\gs-boot.jar; <GigaSpaces Root>\lib\jini\jsk-lib.jar; <GigaSpaces Root>\lib\jini\jsk-platform.jar; <GigaSpaces Root>\lib\openspaces\openspaces.jar; <GigaSpaces Roor>\lib\common\commons-logging.jar; <GigaSpaces Roor>\lib\spring\spring.jar; <GigaSpaces Roor>\lib\spring\jta.jar; <GigaSpaces Roor>\lib\spring\cglib-nodep-2.1_3.jar; You must also include the following JARs from the Hibernate distribution package: jdbc2_0-stdext.jar; dom4j-1.6.1.jar; commons-collections-2.1.1.jar; asm.jar; asm-attrs.jar; antlr-2.7.6rc1.jar; ejb3-persistence.jar; hibernate3.jar; hibernate-annotations.jar; hibernate-commons-annotations.jar 6. Working With a Distributed Cache TopologyGigaSpaces cache provides the following distributed topologies (these are only the most common, many other topologies are supported):
(*) The Partitioned and Embedded Replicated topologies require GigaSpaces eXtreme Application Platform (see Product Info or Download Page) or GigaSpaces XAP Enterprise Data Grid (see Product Info or Download Page) for multiple server nodes. You may evaluate both products for a period of 30 days. Using the Master-Local Cache Topology
jini://*/*/dataGrid?useLocalCache&groups=gigaspaces-6.0XAP
Wait to see the following output in both GSM and GSC console windows: INFO [org.jini.rio.cybernode]: Registered to a ProvisionManager
Wait to see the following output (below the output shown in the previous step) in both GSM and GSC console windows:
FINE [org.jini.rio.monitor.services]: [..\deploy\templates\datagrid:
..\deploy\templates\datagrid.PU] service provisioned, .....
Using the Partitioned Master-Local Cache Topology (Requires GigaSpaces XAP/EDG)
jini://*/*/dataGrid?useLocalCache&groups=gigaspaces-6.0XAP
Wait to see the following output in the two GSC output windows: INFO [org.jini.rio.cybernode]: Registered to a ProvisionManager
Wait to see the following output in the first GSC console window: FINE [org.jini.rio.cybernode]: /datagrid.PU [1]: advertised and the following output in the second GSC console window: FINE [org.jini.rio.cybernode]: /datagrid.PU [2]: advertised
Using the Embedded Replicated Cache Topology (Requires GigaSpaces XAP/EDG)
/./space?cluster_schema=sync_replicated&total_members=2&
id=1&groups=gigaspaces-6.0XAP
/./space?cluster_schema=sync_replicated&total_members=2&
id=2&groups=gigaspaces-6.0XAP
YOU'RE DONE! OPTIONAL: Adding the GigaSpaces In-Memory Data GridIf you need to scale up your database, you can use GigaSpaces as an In-Memory Data Grid. Your application communicates with the Data Grid using the Spring-based Open Spaces framework (or alternatively, using the simple JavaSpaces or Map interfaces). On the back-end, GigaSpaces persists the data to your existing database using your existing Hibernate O/R mapping. NOTE: Adding the GigaSpaces Data Grid requires GigaSpaces eXtreme Application Platform (see Product Info or Download Page) or GigaSpaces XAP Enterprise Data Grid (see Product Info or Download Page) for multiple server nodes. You may evaluate both products for a period of 30 days. Benefits
How to Add the GigaSpaces In-Memory Data GridNOTE: The instructions below assume you are managing your Hibernate configuration using Spring. Refer to the Spring documentation to learn how to do this.
<bean id="hibernateDataSource" class="com.gigaspaces.datasource.hibernate.HibernateDataSource">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<os-core:space id="space" url="/./space" schema="persistent"
external-data-source="hibernateDataSource" />
|
||||||||