Skip to content

Conversation

@lbsekr
Copy link

@lbsekr lbsekr commented Jan 8, 2026

Problem
Since Hibernate ORM 7.2.x, ManagedBeanRegistryImpl enforces that the class returned by ContainedBean::getBeanClass must be identical to the requested bean type.
Spring’s SpringContainedBean currently returns bean.getClass(), which for AOP-proxied beans is a synthetic CGLIB subclass rather than the user-defined type. This mismatch causes Hibernate to throw:

IllegalArgumentException: Bean is not of requested type

Root cause
SpringContainedBean misinterprets the contract of ContainedBean::getBeanClass(): it must return the original target class, not the runtime proxy class.

Solution
Use AopUtils.getTargetClass(bean) instead of bean.getClass() to defer the actual user-defined type of CGLIB/Java-proxy wrapper.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 8, 2026
…s, not a proxy subclass

Signed-off-by: lbsekr <lbsekr@mailbox.org>
@lbsekr
Copy link
Author

lbsekr commented Jan 8, 2026

For context see this conversation with the maintainers of Hibernate-ORM
https://discourse.hibernate.org/t/managedbeanregistryimpl-getbean-in-7-2-0-throwing-exception/12057

@lbsekr lbsekr changed the title Fix Spring-ORM SpringBeanContainer::getBeanClass returns proxy-class instead of target-classs Fix Spring-ORM SpringBeanContainer::getBeanClass returns proxy-class instead of target-class Jan 8, 2026
quaff added a commit to quaff/spring-framework that referenced this pull request Jan 9, 2026
Closes spring-projectsGH-36115

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
@quaff
Copy link
Contributor

quaff commented Jan 9, 2026

@lbsekr I don't think it's a correct fix, I created #36116 including test case.

@lbsekr
Copy link
Author

lbsekr commented Jan 9, 2026

Yes, your fix looks more straightforward

@lbsekr
Copy link
Author

lbsekr commented Jan 9, 2026

I didn't take into account that ultimateTargetClass only defers from proxy-classes but does not retain abstract super type information.

@lbsekr lbsekr closed this Jan 9, 2026
@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 9, 2026
@jhoeller jhoeller added status: superseded An issue that has been superseded by another and removed status: declined A suggestion or change that we don't feel we should currently apply labels Jan 9, 2026
jhoeller pushed a commit that referenced this pull request Jan 9, 2026
Closes GH-36115

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: superseded An issue that has been superseded by another

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants