UnsupportedOperationException using @Any with Spring Boot 3.2.1

Using Spring Boot 3.2.1 and Hibernate 6.4.1.Final causes UnsupportedOperationException with @Any.

Using property like:

  @Any
  @AnyDiscriminator(DiscriminatorType.STRING)
  @AnyDiscriminatorValue(discriminator = "XXX", entity = Xxx.class)
  @AnyDiscriminatorValue(discriminator = "YYY", entity = Yyy.class)
  @AnyDiscriminatorValue(discriminator = "ZZZ", entity = Zzz.class)
  @AnyKeyJavaClass(Long.class)
  @Column(name = "Type")
  @JoinColumn(name = "ReferenceId")
  private Reference reference;

causes:

java.lang.UnsupportedOperationException: null
	at org.hibernate.type.AnyType.setPropertyValues(AnyType.java:382) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.type.CompositeType.replacePropertyValues(CompositeType.java:114) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.type.TypeHelper.replaceAssociations(TypeHelper.java:206) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:532) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:242) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.merge(DefaultMergeEventListener.java:153) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.doMerge(DefaultMergeEventListener.java:143) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:127) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:138) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:888) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:859) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:253) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:243) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:517) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:439) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:224) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:551) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:481) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:442) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:224) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:157) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:513) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:239) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.merge(DefaultMergeEventListener.java:153) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.doMerge(DefaultMergeEventListener.java:143) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:127) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:138) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:888) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:859) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:253) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:243) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:517) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:439) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:224) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:551) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:481) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:442) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:224) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:157) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:573) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:213) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.merge(DefaultMergeEventListener.java:156) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.doMerge(DefaultMergeEventListener.java:143) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:127) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:81) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:867) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:853) ~[hibernate-core-6.4.1.Final.jar:6.4.1.Final]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
	at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:364) ~[spring-orm-6.1.2.jar:6.1.2]
	at jdk.proxy3/jdk.proxy3.$Proxy195.merge(Unknown Source) ~[na:na]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:319) ~[spring-orm-6.1.2.jar:6.1.2]
	at jdk.proxy3/jdk.proxy3.$Proxy195.merge(Unknown Source) ~[na:na]
	at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:621) ~[spring-data-jpa-3.2.1.jar:3.2.1]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:352) ~[spring-aop-6.1.2.jar:6.1.2]
	at org.springframework.data.repository.core.support.RepositoryMethodInvoker$RepositoryFragmentMethodInvoker.lambda$new$0(RepositoryMethodInvoker.java:277) ~[spring-data-commons-3.2.1.jar:3.2.1]
	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:170) ~[spring-data-commons-3.2.1.jar:3.2.1]
	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:158) ~[spring-data-commons-3.2.1.jar:3.2.1]
	at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:516) ~[spring-data-commons-3.2.1.jar:3.2.1]
	at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:285) ~[spring-data-commons-3.2.1.jar:3.2.1]
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:628) ~[spring-data-commons-3.2.1.jar:3.2.1]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.2.jar:6.1.2]
	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:168) ~[spring-data-commons-3.2.1.jar:3.2.1]
	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:143) ~[spring-data-commons-3.2.1.jar:3.2.1]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.2.jar:6.1.2]
	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:70) ~[spring-data-commons-3.2.1.jar:3.2.1]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.2.jar:6.1.2]
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-6.1.2.jar:6.1.2]
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:385) ~[spring-tx-6.1.2.jar:6.1.2]
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-6.1.2.jar:6.1.2]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.2.jar:6.1.2]
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-6.1.2.jar:6.1.2]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.2.jar:6.1.2]
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:164) ~[spring-data-jpa-3.2.1.jar:3.2.1]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.2.jar:6.1.2]
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-6.1.2.jar:6.1.2]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.2.jar:6.1.2]
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:249) ~[spring-aop-6.1.2.jar:6.1.2]
	at jdk.proxy3/jdk.proxy3.$Proxy214.save(Unknown Source) ~[na:na]

reverting to 6.2.17.Final fixes the issue.

        <dependency>
            <groupId>org.hibernate.orm</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.2.17.Final</version>
        </dependency>

Please try to create a reproducer with our test case template (hibernate-test-case-templates/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub) and if you are able to reproduce the issue, create a bug ticket in our issue tracker(https://hibernate.atlassian.net) and attach that reproducer.

Please help me out with this one :pray:. I have tried to create a reproducer with the template you shared, but I was not able to recreate the issue. I have taken minimal Spring Boot setup and did two tests that basically do the same thing, persist with cascade, one using Entity Manager, the other one using JPA repository from Spring Data JPA. With the repository save method fails, while with Entity Manager it doesn’t. I posted the reproducer in https://github.com/spring-projects/spring-data-jpa/issues/3303, but they said it is potentially a Hibernate issue. I guess it has to do with the interaction between Spring and Hibernate, but not really sure. Do you have any suggestions? :jigsaw:

Sorry, but this is a Hibernate forum and people here help with questions about Hibernate. I’m sorry for you if the Spring community is unable to help you with problems in their integration code, but there is nothing I can do.

Hi @weeduck ,

I gave a look at your reproducer and it is enough to change the second persist into a merge in order to reproduce the issue also in Hibernate.

Please open a Jira ticket and attach the reproducer stripped out of all the spring code. Thanks

1 Like

Thank you for the help, you are right, I overlooked I need to use merge. I have opened a Jira ticket [HHH-17621] - Hibernate JIRA.

Cheers