Guenther Demetz (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *commented* on HHH-16557 (
https://hibernate.atlassian.net/browse/HHH-16557?atlOrigin=eyJpIjoiZTc0Yj...
)
Re: NaturalIdCache remains with wrong key-value after create-delete-recreate action (
https://hibernate.atlassian.net/browse/HHH-16557?atlOrigin=eyJpIjoiZTc0Yj...
)
Explanation:
the problem is that with ReadWrite Access strategy the insertion of a new cache entry get
deferred to afterTransactionCompletion.
(see NaturalIdReadWriteAccess.java methods insert and afterInsert).
Thus the order of insert/delete get inverted:
* ActionQueue processes inserts → insertion of a new cache entry get deferred to
afterTransactionCompletion.
* ActionQueue processes deletes→ removal of according cache entry (does not exist yet)
* afterTransactionCompletion process → insertion of a cache entry with obsolete value
Later when creating a new instance with same NaturalId then the cache get not updated
bacause of the existing entry.
As we see in the code below from NaturalIdReadWriteAccess.java the entry will only be
created if not existing already.
@Override
public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object
value) {
try {
writeLock().lock();
Lockable item = (Lockable) getStorageAccess().getFromCache( key, session );
if ( item == null) {
getStorageAccess().putIntoCache(
key,
new Item( value, null, getRegion().getRegionFactory().nextTimestamp() ),
session
);
(
https://hibernate.atlassian.net/browse/HHH-16557#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16557#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:f83bc8f )