diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java index 2a1cfc183b..3a8f0c558c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java @@ -552,53 +552,15 @@ public class GeneratorBinder { final Class generatorClass = idGeneratorType.value(); return creationContext -> { checkGeneratorClass( generatorClass ); - Generator generator; - if ( beanContainer != null ) { - final ContainedBean bean = beanContainer.getBean( - generatorClass, - new BeanContainer.LifecycleOptions() { - @Override - public boolean canUseCachedReferences() { - return false; - } - - @Override - public boolean useJpaCompliantCreation() { - return true; - } - }, - new BeanInstanceProducer() { - @SuppressWarnings("unchecked") - @Override - public B produceBeanInstance(Class beanType) { - return (B) instantiateGenerator( - annotation, - idAttributeMember, - annotationType, - CustomIdGeneratorCreationContext.class, - generatorClass, - creationContext - ); - } - - @Override - public B produceBeanInstance(String name, Class beanType) { - return produceBeanInstance( beanType ); - } - } - ); - generator = bean.getBeanInstance(); - } - else { - generator = instantiateGenerator( - annotation, - beanContainer, - creationContext, - generatorClass, - idAttributeMember, - annotationType - ); - } + final Generator generator = + instantiateGenerator( + annotation, + beanContainer, + creationContext, + generatorClass, + idAttributeMember, + annotationType + ); callInitialize( annotation, idAttributeMember, creationContext, generator ); callConfigure( creationContext, generator ); checkIdGeneratorTiming( annotationType, generator ); @@ -611,7 +573,7 @@ public class GeneratorBinder { BeanContainer beanContainer, CustomIdGeneratorCreationContext creationContext, Class generatorClass, - MemberDetails memberDetails, + MemberDetails idAttributeMember, Class annotationType) { if ( beanContainer != null ) { return instantiateGeneratorAsBean( @@ -619,14 +581,14 @@ public class GeneratorBinder { beanContainer, creationContext, generatorClass, - memberDetails, + idAttributeMember, annotationType ); } else { return instantiateGenerator( annotation, - memberDetails, + idAttributeMember, annotationType, CustomIdGeneratorCreationContext.class, generatorClass, @@ -640,7 +602,7 @@ public class GeneratorBinder { BeanContainer beanContainer, CustomIdGeneratorCreationContext creationContext, Class generatorClass, - MemberDetails memberDetails, + MemberDetails idAttributeMember, Class annotationType) { return beanContainer.getBean( generatorClass, new BeanContainer.LifecycleOptions() { @@ -659,7 +621,7 @@ public class GeneratorBinder { public B produceBeanInstance(Class beanType) { return (B) instantiateGenerator( annotation, - memberDetails, + idAttributeMember, annotationType, CustomIdGeneratorCreationContext.class, generatorClass, @@ -670,8 +632,7 @@ public class GeneratorBinder { public B produceBeanInstance(String name, Class beanType) { return produceBeanInstance( beanType ); } - } ) - .getBeanInstance(); + } ).getBeanInstance(); } private static G instantiateGenerator( diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java index 47996b983e..65364562a5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java @@ -7,7 +7,6 @@ package org.hibernate.boot.model.internal; import java.lang.annotation.Annotation; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -64,10 +63,8 @@ import org.hibernate.service.ServiceRegistry; import org.hibernate.usertype.CompositeUserType; import org.hibernate.resource.beans.container.spi.BeanContainer; -import org.hibernate.resource.beans.internal.Helper; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.service.ServiceRegistry; -import org.hibernate.usertype.CompositeUserType; import org.jboss.logging.Logger; import jakarta.persistence.Basic; @@ -1476,13 +1473,7 @@ public class PropertyBinder { List> generatorAnnotations, List> idGeneratorAnnotations) { for ( AnnotationUsage id : idGeneratorAnnotations ) { - final Iterator> iterator = generatorAnnotations.iterator(); - while ( iterator.hasNext() ) { - final AnnotationUsage gen = iterator.next(); - if ( gen.getAnnotationType().equals( id.getAnnotationType() ) ) { - iterator.remove(); - } - } + generatorAnnotations.removeIf( gen -> gen.getAnnotationType().equals( id.getAnnotationType() ) ); } } }