« Return to Thread: Inserts and Caching

Re: Inserts and Caching

by James Sutherland :: Rate this Message:

Reply to Author | View in Thread

> Does the @Cache NONE actually helps? I wasn't able to find out if the object was cached.

No do not use NONE, to disable the shared cache use shared=false.  NONE should generally only be used for simple objects without relationships.

> Ok, but then the transaction is committed and restarted. In case of a rollback I have "unstable" data since the part before the flush wasn't rolled back.

No flush() does not commit the transaction, only commit() commits the transaction, flush() just writes the SQL to the database, rollback will still rollback everything from the point of the begin().


ossaert wrote:
Thanks for the follow-up.

James Sutherland wrote:
Are you concerned with caching across transaction or within the same transaction?
It is the caching within the same transaction. Let's say in one transaction I have to persist 5000 objects which I do not need afterwards. They should not unnecessary remain in memory. When a couple of requests are running, then the memory is filled up pretty quickly.

Does the @Cache NONE actually helps? I wasn't able to find out if the object was cached.

James Sutherland wrote:
Across transaction you can disable caching using the persistence.xml property,
"eclipselink.cache.shared.default"="false".  Or you can set the size or type of the cache to control how many objects are cached.
Thanks for the tip.

James Sutherland wrote:
For avoiding caching within a single transaction, the best way is to flush() then clear() the EntityManager.  You could do this for each object, or probably better for each batch of objects.
Ok, but then the transaction is committed and restarted. In case of a rollback I have "unstable" data since the part before the flush wasn't rolled back.

Thanks
Jan

 « Return to Thread: Inserts and Caching