Skip to content

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

Open
wants to merge 3 commits into
base: 6.6
Choose a base branch
from

Conversation

gtoison
Copy link
Contributor

@gtoison gtoison commented Nov 27, 2024

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.


gtoison added 2 commits May 27, 2025 13:27
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.
Copy link
Member

@mbellade mbellade left a 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.

Comment on lines 532 to 536
@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() );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@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() );
}

Comment on lines 1207 to 1210

default E getAddedEntry() {
return getAddedInstance();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();
Copy link
Member

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:

Suggested change
return operationQueue.get( index++ ).getAddedEntry();
//noinspection unchecked
return (E) operationQueue.get( index++ ).getAddedEntry();

Copy link
Contributor Author

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<?>?

Copy link
Member

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.

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants