DZone
Java Zone
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
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Enjoy Hibernate Cache

Enjoy Hibernate Cache

Mohammed Amine Tazi user avatar by
Mohammed Amine Tazi
·
Dec. 21, 10 · Java Zone · Interview
Like (0)
Save
Tweet
9.56K Views

Join the DZone community and get the full member experience.

Join For Free

Hibernate is a well-know persistence framework in the  Java world, it comes with a wonderful API to ease application communication with the database.

Caching is a mechanism that stores data so that future requests for that data can be served faster. It’s a good point for performance when there are a lot of requests for the same stuff . Hibernate comes with 3 caching mechanisms to resolve this issue.

First Level Cache

A hibernate session is a unit of work that’s corresponding to a DB transaction. When doing operations on entities, these latters are not stored immediately in DB but wait until the session commits. The hibernate session is hence representing the first level cache and it’s enabled by default.

Second Level Cache

A hibernate SessionFactory aims to create sessions, initializes JDBC connections and pool them. The second level cache lives in the SessionFactory level so all session can share it. This is why it’s called a process scoped cache.

The second level cache is not enabled by default. One has to configure the cache strategy for hibernate entities and the cache provider that will be a third party caching API like EHCache.

Query Cache

This is related to second level cache and is used for caching queries with parameters. It has to be configured like the second level cache.

To know if the application is hitting the cache, you can configure it in the session factory configuration file and begin your unit tests to get an idea of performance.

Enjoy hibernate cache and get to work !!

 

From http://www.misterj2ee.com/2010/12/enjoy-hibernate-cache/

Cache (computing) Hibernate

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What's the Difference Between Static Class vs. Singleton Patterns in C#?
  • 10 Programming Habits a Web Developer Should Embrace
  • 5 Myths of Kubernetes
  • ETL/ELT on Kubernetes With Airbyte

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo