-
Notifications
You must be signed in to change notification settings - Fork 3.6k
HHH-18885 test reproducing the issue #9331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 6.6
Are you sure you want to change the base?
Conversation
hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentMap.java
Outdated
Show resolved
Hide resolved
Extra lazy maps need to persist the added entry (key and value), not the added value. Let PersistentMap.AbstractMapValueDelayedOperation return the added entry so OneToManyPersister.writeIndex() can execute the queued operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, since AbstractPersistentCollection
is also an SPI, I'd rather add the method with the correct signature even in 6.6
.
@Override | ||
public E getAddedEntry() { | ||
// The (E) cast is very hacky because E is not Map.Entry but we need it to conform to PersistentCollection.queuedAdditionIterator() | ||
return (E) Map.entry( getIndex(), getAddedInstance() ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Override | |
public E getAddedEntry() { | |
// The (E) cast is very hacky because E is not Map.Entry but we need it to conform to PersistentCollection.queuedAdditionIterator() | |
return (E) Map.entry( getIndex(), getAddedInstance() ); | |
} | |
@Override | |
public Object getAddedEntry() { | |
return Map.entry( getIndex(), getAddedInstance() ); | |
} |
|
||
default E getAddedEntry() { | ||
return getAddedInstance(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default E getAddedEntry() { | |
return getAddedInstance(); | |
} | |
default Object getAddedEntry() { | |
return getAddedInstance(); | |
} |
@@ -849,7 +849,7 @@ public final Iterator<E> queuedAdditionIterator() { | |||
|
|||
@Override | |||
public E next() { | |||
return operationQueue.get( index++ ).getAddedInstance(); | |||
return operationQueue.get( index++ ).getAddedEntry(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the cast, but move it to here:
return operationQueue.get( index++ ).getAddedEntry(); | |
//noinspection unchecked | |
return (E) operationQueue.get( index++ ).getAddedEntry(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So queuedAdditionIterator()
would still return an Iterator<E>
, right? No an Iterator<?>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's why you need the cast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have moved the cast
Test reproducing the issue: https://hibernate.atlassian.net/browse/HHH-18885
Putting a entity in an extra lazy map and committing the transaction results in a ClassCastException
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.