DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Data
  4. Couchbase JPA Level 2 Cache
Content provided by Couchbase logo

Couchbase JPA Level 2 Cache

Don Pinto user avatar by
Don Pinto
·
Oct. 22, 14 · Interview
Like (0)
Save
Tweet
Share
6.66K Views

Originally written by Justin Michaels

As Couchbase continues to experience growth as a company and increased adoption by the open source community we continue to encounter new challenges and use cases along the way. Many enterprises are turning to us to help add a cache to an existing application or evolve applications to next generation technologies. For these level two cache implementations we’ve helped develop a data access layer for applications in the Spring project. Spring Data Couchbase provides integration with the Couchbase Server cluster by providing POJO centric data interaction with Couchbase Buckets and helping to provide a repository-style implementation. This effort has been very successful and has generated a lot of interest.  

However, there’s more to the story a simple web search for “JPA” uncovers that helps us understand additional needs across the enterprise. While the JPA standard is well defined ultimately each vendor implementation varies enough that supporting specific ORM’s like Eclipselink and Hibernate would require additional work. We engaged our partners at Thumbtack Technology who deployed one of their expert NOSQL development teams to help get the job done. 

The objective was to provide a framework of boilerplate code to leverage Couchbase as a level two cache for both Eclipselink and Hibernate. There are improvements coming with the release of our 2.0 SDK’s and additional integration improvements but we wanted to be able to support these caching efforts in the near term. Both the Hibernate and Eclipselink JPA connectors have been published by Thumbtack on github with test cases to show the configuration.

Hibernate - https://github.com/thumbtack-technology/Couchbase-L2-Hibernate
EclipseLink - https://github.com/thumbtack-technology/Couchbase-L2-EclipseLink

While there is always the ability to leverage Moxi to enable existing memcached clients to be vbubket aware. We knew the javax.persistance package had a cache interface available but each vendor implementation requires nuances that need to be addressed. For example, in reviewing the associated eclipselink documentation shows the ability to add a level 2 cache but nothing that helps us understand the specifics of leveraging a NoSQL solution. Thumbtack helped us solve these configuration challenges.

Eclipselink persistence.xml
<property name="couchbase.cache.servers"
         value="http://couchbase-cluster-node01:8091/pools,
                http://couchbase-cluster-node02:8091/pools"/>                
<property name="couchbase.cache.bucket.name" value="l2-cache"/>
<property name="couchbase.cache.bucket.password" value="cachepwd"/>
<property name="couchbase.cache.ttl" value="600"/>

<property name="eclipselink.descriptor.customizer.<ENTITY>"
              value="net.thumbtack.couchbase.eclipselink.ClassCustomizer"/>
<-- Example for test cases —>
<property name="eclipselink.descriptor.customizer.Order"
             value="net.thumbtack.couchbase.eclipselink.ClassCustomizer"/>              

<-- each entity needs a Class Customizer -->
<property name="eclipselink.descriptor.customizer.<ENTITY>"
              value="net.thumbtack.couchbase.eclipselink.ClassCustomizer"/>
Hibernate persistence.xml
<property name="couchbase.cache.servers"
         value="http://couchbase-cluster-node01:8091/pools,
                http://couchbase-cluster-node02:8091/pools"/>                
<property name="couchbase.cache.bucket.name" value="l2-cache"/>
<property name="couchbase.cache.bucket.password" value="cachepwd"/>
<property name="couchbase.cache.ttl" value="600"/>

<property name="hibernate.cache.region.factory_class" value="com.googlecode.hibernate.memcached.MemcachedRegionFactory" />
<property name="hibernate.memcached.memcacheClientFactory" value="net.thumbtack.hibernate.couchbase.CouchbaseClientFactory" />

Additional details in getting the Thumbtack test cases running locally can be found in the github repositories. 

These connectors provide us the ability to extend existing applications by adding an object cache with a durable cluster. By leveraging the power of Couchbase we can prevent Cold Cache, dramatically reduce load on your RDBMS, auto-shard across the cluster and provide a durable object store.


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: