Skip to content
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

Hibernate Entity containing elementcollection of embeddables having embeddable crashes in HibernateJpaProvider #1886

Closed
rmschots opened this issue Apr 4, 2024 · 7 comments
Assignees
Labels
component: core kind: bug worth: high Implementing this has a high worth
Milestone

Comments

@rmschots
Copy link

rmschots commented Apr 4, 2024

Description

In a spring boot environment, when creating an entity with an elementcollection of embeddables that have an embeddable, I'm getting an error when running the application.
I encounter this error when creating a project from the spring boot archetype, and adapting it to spring boot 3.2.4, replacing javax with jakarta, and creating a simple entity structure:

Organization has many OrganizationBankAccount as ElementCollection
OrganizationBankAccount has an Embedded SwiftCode
SwiftCode contains a single String field

@Entity
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Organization {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", nullable = false)
    private UUID id;

    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "organization_bank_account", joinColumns = @JoinColumn(name = "organization_id"))
    @Builder.Default
    @Setter(AccessLevel.PRIVATE)
    private Set<OrganizationBankAccount> bankAccounts = new HashSet<>();
}

@Embeddable
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrganizationBankAccount {
    @Embedded
    @AttributeOverride(name = "value", column = @Column(name = "swift_code"))
    private SwiftCode swiftCode;
}

@Getter
@Setter
@Embeddable
@ToString
@EqualsAndHashCode
public class SwiftCode {
    private String value;

    public static SwiftCode of(String swiftCode) {
        return new SwiftCode(swiftCode);
    }

    protected SwiftCode() {
    }

    private SwiftCode(String swiftCode) {
        this.value = swiftCode;
    }
}

Expected behavior

The blaze persistence should allow this kind of structure without crashing

Actual behavior

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
	at org.hibernate.type.ComponentType.getCascadeStyle(ComponentType.java:564) ~[hibernate-core-6.4.4.Final.jar:6.4.4.Final]
	at com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.isOrphanRemoval(HibernateJpaProvider.java:1275) ~[blaze-persistence-integration-hibernate6-base-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.EntityMetamodelImpl$AttributeEntry.<init>(EntityMetamodelImpl.java:1057) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.EntityMetamodelImpl.collectColumnNames(EntityMetamodelImpl.java:418) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.EntityMetamodelImpl.collectColumnNames(EntityMetamodelImpl.java:357) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.EntityMetamodelImpl.collectColumnNames(EntityMetamodelImpl.java:378) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.EntityMetamodelImpl.<init>(EntityMetamodelImpl.java:127) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.CriteriaBuilderFactoryImpl.<init>(CriteriaBuilderFactoryImpl.java:110) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.CriteriaBuilderConfigurationImpl.createCriteriaBuilderFactory(CriteriaBuilderConfigurationImpl.java:2140) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.rmschots.blazedemo.config.BlazePersistenceConfiguration.createCriteriaBuilderFactory(BlazePersistenceConfiguration.java:48) ~[classes/:na]
	at com.rmschots.blazedemo.config.BlazePersistenceConfiguration$$SpringCGLIB$$0.CGLIB$createCriteriaBuilderFactory$1(<generated>) ~[classes/:na]
	at com.rmschots.blazedemo.config.BlazePersistenceConfiguration$$SpringCGLIB$$FastClass$$1.invoke(<generated>) ~[classes/:na]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258) ~[spring-core-6.1.5.jar:6.1.5]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-6.1.5.jar:6.1.5]
	at com.rmschots.blazedemo.config.BlazePersistenceConfiguration$$SpringCGLIB$$0.createCriteriaBuilderFactory(<generated>) ~[classes/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140) ~[spring-beans-6.1.5.jar:6.1.5]

debug details right before the crash:
image
image

Steps to reproduce

check out my sample repo and run the application:
https://github.com/rmschots/blaze-persistence-demo

Environment

Version: 1.6.11
JPA-Provider: Hibernate 6.4
DBMS: H2
Application Server: Spring boot 3.2.4

FYI: I had the same problem when I was using Spring 3.1 and Hibernate 6.2

@beikov beikov added this to the 1.6.12 milestone Apr 8, 2024
@beikov beikov added kind: bug component: core worth: high Implementing this has a high worth labels Apr 8, 2024
@beikov
Copy link
Member

beikov commented Apr 8, 2024

Thanks for the report. We'll try to look into this as soon as possible.

@beikov beikov modified the milestones: 1.6.12, 1.6.13 Aug 2, 2024
@beikov beikov modified the milestones: 1.6.13, 2.0.1 Nov 4, 2024
@RustamSultansoy
Copy link

RustamSultansoy commented Nov 5, 2024

any updates here? @beikov
same happens in quarkus 3+ with hibernate 6
i've tested on several versions of quarkus3: 3.2 (hibernate 6.2.18), 3.8 (hibernate 6.4.8)

@RustamSultansoy
Copy link

for my applications this line instead of return fixed the problem:
return componentType.getCascadeStyle(componentType.getPropertyIndex(propertyParts[propertyIndex])).hasOrphanDelete();

sultansoy added a commit to sultansoy/blaze-persistence that referenced this issue Nov 5, 2024
@EugenMayer
Copy link
Contributor

FYI, we are using hibernate 6.6.1, sb 3.3.5 and also using ElementCollection and we have no issues here with 1.6.13 (of course)

sultansoy added a commit to sultansoy/blaze-persistence that referenced this issue Nov 6, 2024
beikov pushed a commit that referenced this issue Nov 6, 2024
@beikov beikov modified the milestones: 2.0.1, 1.6.14 Nov 6, 2024
@beikov beikov closed this as completed Nov 6, 2024
@beikov
Copy link
Member

beikov commented Nov 6, 2024

@rmschots can you please check and report back if 1.6.14-SNAPSHOT fixes the problems you encountered?

@rmschots
Copy link
Author

rmschots commented Nov 6, 2024

@beikov just checked. Works with 1.6.14-SNAPSHOT. Thanks

@beikov
Copy link
Member

beikov commented Nov 6, 2024

Thanks for confirming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core kind: bug worth: high Implementing this has a high worth
Projects
None yet
Development

No branches or pull requests

4 participants