HHH-18164 Make @IdGeneratorType respect BeanContainer
This commit is contained in:
parent
dfed5a9d25
commit
e96741cfa6
|
@ -65,8 +65,8 @@ import org.hibernate.models.spi.ClassDetails;
|
||||||
import org.hibernate.models.spi.MemberDetails;
|
import org.hibernate.models.spi.MemberDetails;
|
||||||
import org.hibernate.mapping.Value;
|
import org.hibernate.mapping.Value;
|
||||||
import org.hibernate.resource.beans.container.spi.BeanContainer;
|
import org.hibernate.resource.beans.container.spi.BeanContainer;
|
||||||
|
import org.hibernate.resource.beans.container.spi.ContainedBean;
|
||||||
import org.hibernate.resource.beans.spi.BeanInstanceProducer;
|
import org.hibernate.resource.beans.spi.BeanInstanceProducer;
|
||||||
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
|
|
||||||
|
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
@ -552,14 +552,53 @@ public class GeneratorBinder {
|
||||||
final Class<? extends Generator> generatorClass = idGeneratorType.value();
|
final Class<? extends Generator> generatorClass = idGeneratorType.value();
|
||||||
return creationContext -> {
|
return creationContext -> {
|
||||||
checkGeneratorClass( generatorClass );
|
checkGeneratorClass( generatorClass );
|
||||||
final Generator generator = instantiateGenerator(
|
Generator generator;
|
||||||
annotation,
|
if ( beanContainer != null ) {
|
||||||
beanContainer,
|
final ContainedBean<? extends Generator> bean = beanContainer.getBean(
|
||||||
creationContext,
|
generatorClass,
|
||||||
generatorClass,
|
new BeanContainer.LifecycleOptions() {
|
||||||
idAttributeMember,
|
@Override
|
||||||
annotationType
|
public boolean canUseCachedReferences() {
|
||||||
);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean useJpaCompliantCreation() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new BeanInstanceProducer() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public <B> B produceBeanInstance(Class<B> beanType) {
|
||||||
|
return (B) instantiateGenerator(
|
||||||
|
annotation,
|
||||||
|
idAttributeMember,
|
||||||
|
annotationType,
|
||||||
|
CustomIdGeneratorCreationContext.class,
|
||||||
|
generatorClass,
|
||||||
|
creationContext
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <B> B produceBeanInstance(String name, Class<B> beanType) {
|
||||||
|
return produceBeanInstance( beanType );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
generator = bean.getBeanInstance();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
generator = instantiateGenerator(
|
||||||
|
annotation,
|
||||||
|
beanContainer,
|
||||||
|
creationContext,
|
||||||
|
generatorClass,
|
||||||
|
idAttributeMember,
|
||||||
|
annotationType
|
||||||
|
);
|
||||||
|
}
|
||||||
callInitialize( annotation, idAttributeMember, creationContext, generator );
|
callInitialize( annotation, idAttributeMember, creationContext, generator );
|
||||||
callConfigure( creationContext, generator );
|
callConfigure( creationContext, generator );
|
||||||
checkIdGeneratorTiming( annotationType, generator );
|
checkIdGeneratorTiming( annotationType, generator );
|
||||||
|
|
|
@ -63,6 +63,11 @@ import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.usertype.CompositeUserType;
|
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 org.jboss.logging.Logger;
|
||||||
|
|
||||||
import jakarta.persistence.Basic;
|
import jakarta.persistence.Basic;
|
||||||
|
|
Loading…
Reference in New Issue