开发者

Basic Hibernate Caching Question

开发者 https://www.devze.com 2022-12-27 18:52 出处:网络
Does Hibernate use cache (second level or otherwise) if all I am doing is batch inserts? No entities are being requested from the database, and no generators are used.

Does Hibernate use cache (second level or otherwise) if all I am doing is batch inserts? No entities are being requested from the database, and no generators are used. Also, would StatelessSession vs Session cha开发者_如何学运维nge the answer? What if I was using a Session with a JDBC batch size of 50? The cache I will be using is Ehcache


Doe Hibernate use cache (second level or otherwise) if all I am doing is batch inserts?

Newly inserted Entities instances are cached in the L1 cache (the session-level cache) before they are flushed to the database (see the section 13. Batch processing), hence the need to flush and clear your session regularly to prevent OOM.

Also, would StatelessSession vs Session change the answer?

Yes. As written in section 13.3. The StatelessSession interface : A StatelessSession has no persistence context associated with it and does not provide many of the higher-level life cycle semantics. In particular, a stateless session does not implement a first-level cache nor interact with any second-level or query cache.

What if I was using a Session with a JDBC batch size of 50?

This just means that you should flush/clear the session every 50 insert.

0

精彩评论

暂无评论...
验证码 换一张
取 消