1

I am using Hibernate 4, JSF, and Spring in my project.

I have tables like: ValidStatus, Valid Group, ValidAccess, in which I already populated some default data.

I have to put all these tables data in the Cache so that, anytime in different pages, I can use these table for authorizing users.

How can we cache these table data? Do I have to use the Second-Level Cache for this scenario or something else will work as well?

2 Answers 2

2

The first level cache is only valid for as long as the current running Session (a.k.a EntityManager) is open.

Two concurrent transactions will run in different Session(s), hence each one will have it's own 1st Level Cache, which is not what you aim for.

You want the 2nd Level Cache, which is shared between concurrent Session(s):

  • EhCache is a very well-known 2nd Level Cache implementation,
  • Infinispan which is developed by Red Hat.
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks any gud Example how to integrate with JSf+Spring Application?
0

Hibernate has default cahching capability.

Hibernate first level cache is Session level cache, so if the object is currently in the Hibernate session results will be fetched from it.

Therefore, yoou do not need to cache fetched results, it is already cached by hibernate.

See also

https://stackoverflow.com/a/20369520/892994

Hibernate Caching

1 Comment

But i want only Valid table data be in Cache not every table or query data store in Cache

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.