Trying to find out if what I’m doing is legal according to spec or some sort of bug.
I’m using Quarkus 2.13.3 and Hibernate 5.6.12 via quarkus-hibernate-orm extension.
This class hierarchy fails:
@Entity
public class Foo implements Serializable {
@Id
@GeneratedValue
String id;
@ElementCollection
Set<Bar> bars;
}
@Embeddable
public class Bar {
@Embedded
Baz baz;
}
@Embeddable
class Baz {
String property;
}
I get the error:
2022-10-25 16:01:06,124 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile dev): java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.hibernate.persister.collection.AbstractCollectionPersister.generateSelectSizeString(AbstractCollectionPersister.java:1048)
at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:522)
at org.hibernate.persister.collection.BasicCollectionPersister.<init>(BasicCollectionPersister.java:59)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:152)
at org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:140)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:226)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:319)
at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:74)
at io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:72)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at io.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:165)
at io.quarkus.hibernate.orm.runtime.JPAConfig$1.run(JPAConfig.java:66)
at java.base/java.lang.Thread.run(Thread.java:833)
I don’t know if it helps but earlier in the process there’s this:
2022-10-25 16:01:05,544 DEBUG [org.hib.cfg.CollectionSecondPass] (Quarkus Main Thread) Second pass for collection: com.example.Foo.bars
2022-10-25 16:01:05,544 DEBUG [org.hib.cfg.ann.CollectionBinder] (Quarkus Main Thread) Binding a collection of element: com.example.Foo.bars
2022-10-25 16:01:05,547 DEBUG [org.hib.cfg.Ejb3Column] (Quarkus Main Thread) Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Foo_bars), mappingColumn=baz, insertable=true, updatable=true, unique=false}
2022-10-25 16:01:05,547 DEBUG [org.hib.cfg.ann.PropertyBinder] (Quarkus Main Thread) Building property baz
2022-10-25 16:01:05,548 DEBUG [org.hib.map.PrimaryKey] (Quarkus Main Thread) Forcing column [foo_id] to be non-null as it is part of the primary key for table [foo_bars]
2022-10-25 16:01:05,548 DEBUG [org.hib.cfg.CollectionSecondPass] (Quarkus Main Thread) Mapped collection key: Foo_id, element:
If try to embed a single Bar (and Baz…) into Foo directly, it works fine, I end up with a column “property” in the foo table, so nested Embeddables work there.
If I try to embed a Set of Baz (which just has basic fields), it works fine.
What isn’t working is an ElementCollection of Embeddable that has any Embedded properties. Is it supposed to?
On logicbig (JPA + Hibernate - Persisting Collections of embeddable type by using @ElementCollection), it implies it should, but I haven’t really found anything else saying yes or no:
Note that all cases of @Embeddable class are applied here: we can use an embeddable class within another one, the embeddable can have entity relationship and/or we can also use multiple instances of same embeddable type collection in our entity.