views:

71

answers:

1

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 change the answer? What if I was using a Session with a JDBC batch size of 50? The cache I will be using is Ehcache

+2  A: 

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.

Pascal Thivent