Skip to content

Scoped EntityManager bean cannot get unwrapped to Session (with Hibernate 5.2) [SPR-15010] #19577

Closed
@spring-projects-issues

Description

@spring-projects-issues

Rodolfo Labsch opened SPR-15010 and commented

Cannot cast spring created proxy to a different object interface.
e.g.:
Given the bean:
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public EntityManager myEntityManager(EntityManagerFactory emf) {
return emf.createEntityManager();
}

If I try to cast it or maybe unwrap the instance, we get a class cast exception:
@Autowired
EntityManager em;

Session s = em.unwrap(Session.class) -> ClassCastException
Session s = ((Session) em) -> ClassCastException


Affects: 4.2.8

Issue Links:

Referenced from: commits 6d1cae2, d15df34

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions