Default cache used by Hibernate?

梦想与她 提交于 2020-01-12 04:00:06

问题


What is the name of the default cache used by Hibernate? Is there a default cache even, or do you have to add a cache provider in order to take advantage of a cache?

I thought it was the EHCache but I think this has to be configured...it is not "there" by default...


回答1:


Hibernate already provides a caching mechanisms called 1st level cache by the persistent context . It is in the Session scoped , enabled by default and cannot be turned off.

The cache provider such as EHCache provides another caching mechanisms called 2nd level cache . It is in the SessionFactory scoped . No 2nd level cache is enable by default and you have to configure it .

See this for how to enable EHCache in hibernate.




回答2:


No second level cache is enabled in hibernate by default.

You can always choose one of these cache providers according to your needs:

  • EHCache
  • OSCache
  • SwarmCache
  • Jboss TreeCache
  • JBoss Cache 2

You can always refer to hibernate documentation to see how to register it.



来源:https://stackoverflow.com/questions/7349530/default-cache-used-by-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!