Retain original requested bean class for SpringContainedBean

Closes GH-36115

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
This commit is contained in:
Yanming Zhou
2026-01-09 19:52:22 +01:00
committed by Juergen Hoeller
parent 38a397873e
commit d3a385d222
2 changed files with 42 additions and 19 deletions
@@ -33,6 +33,7 @@ import org.springframework.orm.jpa.hibernate.beans.BeanSource;
import org.springframework.orm.jpa.hibernate.beans.MultiplePrototypesInSpringContextTestBean;
import org.springframework.orm.jpa.hibernate.beans.NoDefinitionInSpringContextTestBean;
import org.springframework.orm.jpa.hibernate.beans.SinglePrototypeInSpringContextTestBean;
import org.springframework.orm.jpa.hibernate.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -42,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*
* @author Yoann Rodiere
* @author Juergen Hoeller
* @author Yanming Zhou
*/
class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests
extends AbstractEntityManagerFactoryIntegrationTests {
@@ -275,6 +277,20 @@ class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests
));
}
@Test
void testRetrieveBeanShouldRetainOriginalBeanType() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
ContainedBean<TestBean> bean = beanContainer.getBean(
"single", TestBean.class,
NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE
);
assertThat(bean).isNotNull();
assertThat(bean.getBeanClass()).isSameAs(TestBean.class);
}
/**
* The lifecycle options mandated by the JPA spec and used as a default in Hibernate ORM.