HHH-15966 ElementCollection with nested Embeddables fails with ArrayIndexOutOfBoundsException

This commit is contained in:
Andrea Boriero 2023-01-12 12:12:41 +01:00 committed by Christian Beikov
parent 00018731f8
commit b774f80ce9
5 changed files with 15 additions and 14 deletions

View File

@ -2172,12 +2172,20 @@ public abstract class CollectionBinder {
CollectionPropertyHolder holder,
Class<? extends CompositeUserType<?>> compositeUserType) {
//TODO be smart with isNullable
final AccessType accessType = accessType( property, collection.getOwner() );
// We create a new entity binder here because it is needed for processing the embeddable
// Since this is an element collection, there is no real entity binder though,
// so we just create an "empty shell" for the purpose of avoiding null checks in the fillEmbeddable() method etc.
final EntityBinder entityBinder = new EntityBinder();
// Copy over the access type that we resolve for the element collection,
// so that nested components use the same access type. This fixes HHH-15966
entityBinder.setPropertyAccessType( accessType );
final Component component = fillEmbeddable(
holder,
getSpecialMembers( elementClass ),
accessType( property, collection.getOwner() ),
accessType,
true,
new EntityBinder(),
entityBinder,
false,
false,
true,

View File

@ -2253,9 +2253,11 @@ public class EntityBinder {
public AccessType getExplicitAccessType(XAnnotatedElement element) {
AccessType accessType = null;
final Access access = element.getAnnotation( Access.class );
if ( access != null ) {
accessType = AccessType.getAccessStrategy( access.value() );
if ( element != null ) {
final Access access = element.getAnnotation( Access.class );
if ( access != null ) {
accessType = AccessType.getAccessStrategy( access.value() );
}
}
return accessType;
}

View File

@ -33,7 +33,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class FieldAccessedNestedEmbeddableMetadataTest {
@Test
@FailureExpected(jiraKey = "HHH-9089")
public void testEnumTypeInterpretation() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();

View File

@ -48,10 +48,6 @@ public class NestedEmbeddableDefaultAccessTests {
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-14063" )
@FailureExpected(
reason = "When an embeddable is a key or element of a collection, access-type is " +
"not properly propagated to nested embeddables"
)
public void verifyElementCollectionMapping(DomainModelScope scope) {
scope.withHierarchy( MyEntity.class, (descriptor) -> {
final Property outerEmbeddedList = descriptor.getProperty( "outerEmbeddableList" );

View File

@ -63,7 +63,6 @@ public class Component4 {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
@ -80,9 +79,6 @@ public class Component4 {
Component4 other = (Component4) obj;
if ( description != null ? !description.equals( other.description ) : other.description != null ) {
return false;
}
if ( key != null ? !key.equals( other.key ) : other.key != null ) {
return false;
}