Given a base entity
{code:java}@Entity(name = "catalog_value") @Cacheable @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) @Immutable public class CatalogValue {
@EmbeddedId @AttributeOverride(name = "uuid", column = @Column(name = "id", updatable = false, nullable = false, columnDefinition = "CHAR(36)")) private CatalogValueId id; // don't make final to not break hibernate
@Immutable @ElementCollection @CollectionTable(name = "catalog_value_metadata", joinColumns = { @JoinColumn(name = "catalog_value_id", referencedColumnName = "id") }) @MapKeyColumn(name = "`key`") @AttributeOverride(name = "value.value", column = @Column(name = "`value`")) @AttributeOverride(name = "value.isPublic", column = @Column(name = "is_public")) @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) private Map<String, MetadataValue> metadata = new HashMap<>(); [...] }{code}
this test case
{noformat} @Test public void metadataBug() { final var bav = findByKey("DE-BY"); // has metadata findByKey("DE"); // has NO metadata (which should be totally fine, according to entity) bav.getMetadata().size(); }{noformat}
leads to
{quote}java.lang.IllegalArgumentException: Can not set java.util.UUID field org.example.entity.catalog.CatalogValueId.uuid to org.hibernate.engine.spi.CollectionKey{quote}
Reproducer: [https://github.com/mickroll/hibernate-test-case-templates/tree/elementcollection-and-caching-and-embeddedid|https://github.com/mickroll/hibernate-test-case-templates/tree/elementcollection-and-caching-and-embeddedid|smart-link]
simply build using:
{noformat}cd orm/hibernate-orm-6 mvn clean install{noformat}
Full stack trace:
{quote}Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.331 sec <<< FAILURE! metadataBug(org.hibernate.bugs.HibernateReproducerTest) Time elapsed: 1.258 sec <<< ERROR! org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.util.UUID org.example.entity.catalog.CatalogValueId.uuid] by reflection for persistent property [org.example.entity.catalog.CatalogValueId#uuid] : CollectionKey[org.example.entity.catalog.CatalogValue.metadata#component[uuid]{uuid=00000001-0000-0001-0000-000000000000}] at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:50) at org.hibernate.metamodel.mapping.internal.AbstractEmbeddableMapping.getValues(AbstractEmbeddableMapping.java:99) at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:447) at org.hibernate.type.ComponentType.disassemble(ComponentType.java:666) at org.hibernate.cache.internal.DefaultCacheKeysFactory.staticCreateCollectionKey(DefaultCacheKeysFactory.java:50) at org.hibernate.cache.internal.DefaultCacheKeysFactory.createCollectionKey(DefaultCacheKeysFactory.java:103) at org.hibernate.cache.spi.support.AbstractCollectionDataAccess.generateCacheKey(AbstractCollectionDataAccess.java:38) at org.hibernate.sql.results.internal.ResultsHelper.addCollectionToCache(ResultsHelper.java:285) at org.hibernate.sql.results.internal.ResultsHelper.finalizeCollectionLoading(ResultsHelper.java:203) at org.hibernate.loader.ast.internal.AbstractCollectionBatchLoader.finishInitializingKey(AbstractCollectionBatchLoader.java:86) at org.hibernate.loader.ast.internal.CollectionBatchLoaderArrayParam.loadEmbeddable(CollectionBatchLoaderArrayParam.java:155) at org.hibernate.loader.ast.internal.CollectionBatchLoaderArrayParam.load(CollectionBatchLoaderArrayParam.java:109) at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:680) at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:75) at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127) at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1702) at org.hibernate.collection.spi.AbstractPersistentCollection.lambda$initialize$3(AbstractPersistentCollection.java:617) at org.hibernate.collection.spi.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:265) at org.hibernate.collection.spi.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:615) at org.hibernate.collection.spi.AbstractPersistentCollection.read(AbstractPersistentCollection.java:136) at org.hibernate.collection.spi.AbstractPersistentCollection.lambda$readSize$0(AbstractPersistentCollection.java:163) at org.hibernate.collection.spi.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:265) at org.hibernate.collection.spi.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:148) at org.hibernate.collection.spi.PersistentMap.size(PersistentMap.java:130) at org.hibernate.bugs.HibernateReproducerTest.metadataBug(HibernateReproducerTest.java:34) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Caused by: java.lang.IllegalArgumentException: Can not set java.util.UUID field org.example.entity.catalog.CatalogValueId.uuid to org.hibernate.engine.spi.CollectionKey at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58) at java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36) at java.base/java.lang.reflect.Field.get(Field.java:425) at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:46) ... 58 more
Results :
Tests in error: metadataBug(org.hibernate.bugs.HibernateReproducerTest): Error accessing field [private java.util.UUID org.example.entity.catalog.CatalogValueId.uuid] by reflection for persistent property [org.example.entity.catalog.CatalogValueId#uuid] : CollectionKey[org.example.entity.catalog.CatalogValue.metadata#component[uuid]{uuid=00000001-0000-0001-0000-000000000000}]{quote} |
|