Integrating TayzGrid into Hibernate solves database scalability limitations for high traffic applications. Your applications benefit from high availability, high scalability and zero data loss. These benefits are essential when using Hibernate in a clustered environment. Furthermore, TayzGrid can be easily plugged into Hibernate using config changes without any code change.
Hibernate is one of the most famous Object Relational Mapping library for Java. Having its own native API, and being JPA compliant (Java Persistence API compliant), it supports almost every type of database. It auto-generates classes by mapping domain objects to your database tables, rows and columns using normal Object Oriented idioms such as interfaces, inheritance, Java collections etc. Hibernate also translates Java domain object query syntax into SQL queries. It makes development easier and faster and is built to support high transactions. However, applications soon face scalability bottlenecks in the database tier. To take load off the database, Hibernate provides a sophisticated two level caching mechanism to cache frequently used application data.
The Hibernate First Level Cache resides in-memory, inside your application, and lives within the session scope. Its primary function is to reduce the number of redundant SQL queries within a transaction thus avoiding unnecessary database trips. Itís enabled by default and you cannot disable it. Although this helps improve the overall read performance, the problem still remains: databases cannot scale well at higher transactional load.
The Hibernate Second Level Cache is the fallback if the requested objects are not found in the first level cache. The Second Level Cache can be configured for every class and collection which you intend to store in the database, giving you complete data control. Second Level Caching is mainly used to store objects across sessions, as it lives within the Session Factory scope, so cached objects are available to the entire application. In a clustered environment, cached data needs to be available out-of-application so that other instances of applications, running on other servers, can utilize the same data thereby reducing the amount of database trips.
Both TayzGrid and Hibernate Second Level Cache live outside your application scope, therefore the TayzGrid/Hibernate cache outlives the application lifetime. This allows you to keep the cache live even if your application process restarts. Additionally, with TayzGrid you can have multiple application processes in a multi-server web farm share a common second level cache. Using the TayzGrid IMDG your N-Tier architecture will now boast high availability in the case of any server failure. It will boast high performance throughput since the data is distributed, thereby reducing the amount of database traffic by up to 80%.
You can plug-in TayzGrid as Hibernate Second Level Cache without any programming or even recompilation of your code. You only need to modify app.config file as follows.
<hibernate-configuration> <session-factory> ... <property name="hibernate.cache.use_second_level_cache"> true </property> <property name="hibernate.cache.region.factory_class"> com.alachisoft.tayzgrid.integrations.hibernate.cache.TayzGridRegionFactory </property> <property name="tayzgrid.application_id"> myapp </property> <property name="hibernate.cache.use_query_cache"> true </property> ... </session-factory> </hibernate-configuration> <!--2nd section --> <hibernate-mapping> <class name="hibernator.BLL.Customer" table="customers"> <cache usage="read-write" region="AbsoluteExpirationRegion"/> ... </class> </hibernate-mapping>
And, here in Customer.hbm.xml, you specify if Hibernate Second Level Cache should store this class in TayzGrid. You do this for each class that Hibernate is using.
<hibernate-mapping> <class name="hibernator.BLL.Customer" table="customers"> <cache usage="read-write" region="AbsoluteExpirationRegion"/> ... </class> </hibernate-mapping>
And, below in TayzGridHibernate.xml you can specify TayzGrid configuration for Hibernate.
<configuration> <application-config application-id="myapp" enable-cache-exception="true" default-region-name="DefaultRegion" key-case-sensitivity="false"> <cache-regions> ... <region name="DefaultRegion" cache-name="mycache" priority="default" expiration-type="none" expiration-period="0"/> </cache-regions> <database-dependencies> <dependency entity-name="hibernator.BLL.Customer" type="oledb" sql-statement="select ContactName from dbo.Customers where CustomerID =?" cache-key-format="depdency.customer:[pk]"/> </database-dependencies> </application-config> </configuration>
Despite the fact that Hibernate Second Level Cache provider makes it really easy for you to incorporate TayzGrid into your Java application, you should keep in mind that you only get a subset of TayzGrid features through this integration. If you make direct API calls into TayzGrid through a small programming effort, you would gain the following features.