Thanks Emmanuel!
I have digg a little deeper on my problem, as I can see, enable 'cache' on the
huge collection list (property) will not solve my problem.
From the hibernate cache logging message, I can see that, whenever I update the
list
alarm.getRecords().add(newRecord);
Hibernate will lookup the list by a join on the assoc. table and the 'record' entity table.
When persists with entity manager, the cache is invalidated!!!
As a result, caching the collection does nothing.
So, now my question is now becoming two different questions, either one should help me
to overcome the performance problem I have!!
One:
Is it possible to configure hibernate such that, when it want to load the collection,
it only lookup the assocation table (DO NOT JOIN THE OTHER END OF THE RELATION),
then, use the entity id from the assocation table and lookup in the cache.
Two:
Is it LazyCollection(LazyCollectionOption.EXTRA) work on @ManyToMany relation?
If yes, does it have different behavour of 'Set' or 'List' collection.
More important, I have found some other mention that, with lazy="extra" option,
size() method of the collectio would not trigger hibernate to load the complete
collection from DB. However, how about "add()".
In my use case, the collection is huge, but my only operation is "add()".
(ie. the collection is NEVER shrink).
How to configure hibernate so that, when new element add, only 'INSERT' statement
will be issued, but not load collection and then insert.
Is there any special requirement for lazy="extra" to work?
Is it not work for owning side of the association?
|