@NotFound used with @OneToMany error

We are upgrading our application to Hibernate 6.1.7 and got the same error as reported here:
HHH-16258

So we tested to use Hibernate Core 6.2.0.CR4 to see if the above error was fixed but with that version our application does not even start anymore due to this error:
Caused by: org.hibernate.AnnotationException: Collection 'com.perfri.testapp.jpa.entity.Carrier.projects' annotated '@NotFound' is not a '@ManyToMany' association

We have lots of bidirectional relations in our application that uses @OneToMany and @ManyToOne together with @NotFound(IGNORE) but according to this exception it seems not to be okay anymore?

Stacktrace from the error is here:

Caused by: org.hibernate.AnnotationException: Collection 'com.perfri.testapp.jpa.entity.Carrier.projects' annotated '@NotFound' is not a '@ManyToMany' association
	at org.hibernate.boot.model.internal.CollectionBinder.notFoundAction(CollectionBinder.java:364) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.internal.CollectionBinder.bindCollection(CollectionBinder.java:282) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.internal.PropertyBinder.bindProperty(PropertyBinder.java:851) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.internal.PropertyBinder.buildProperty(PropertyBinder.java:765) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.internal.PropertyBinder.processElementAnnotations(PropertyBinder.java:686) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.internal.EntityBinder.processIdPropertiesIfNotAlready(EntityBinder.java:961) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.internal.EntityBinder.handleIdentifier(EntityBinder.java:302) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.internal.EntityBinder.bindEntityClass(EntityBinder.java:228) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.internal.AnnotationBinder.bindClass(AnnotationBinder.java:417) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:255) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:271) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:314) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1380) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1451) ~[hibernate-core-6.2.0.CR4.jar:6.2.0.CR4]
	at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:66) ~[spring-orm-6.0.6.jar:6.0.6]
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376) ~[spring-orm-6.0.6.jar:6.0.6]
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-6.0.6.jar:6.0.6]
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-6.0.6.jar:6.0.6]
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352) ~[spring-orm-6.0.6.jar:6.0.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1808) ~[spring-beans-6.0.6.jar:6.0.6]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-6.0.6.jar:6.0.6]
	... 124 common frames omitted

This annotation never did anything for @OneToMany or @ManyToMany, and we wanted to tell users to get rid of it, since it might be confusing to readers of the model, giving a wrong impression about behavior.

1 Like