Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring ORM doesn't support addNamedQuery with EclipseLink [SPR-13957] #18530

Closed
spring-projects-issues opened this issue Feb 18, 2016 · 3 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 18, 2016

Lukáš Vasek opened SPR-13957 and commented

Hello,
I'm trying to add together spring boot (1.3.2) + eclpselink (2.6.2) + axon framework.
Axon has in it's https://github.com/AxonFramework/AxonFramework/blob/df54dcf98807751a0368ee2e9906879b7f495330/core/src/main/java/org/axonframework/saga/repository/jpa/JpaSagaRepository.java class this construction

entityManagerFactory.addNamedQuery(LOAD_SAGA_NAMED_QUERY, entityManager.createQuery(LOAD_SAGA_QUERY));

which leads to classcast exception. I'm wondering if this is springs or eclipselinks issue.

Thanks

Lukas


Affects: 4.2.4

Reference URL: http://stackoverflow.com/questions/35455351/eclipselink-not-compatible-with-spring

Issue Links:

Referenced from: commits 7fcb277, 4320161

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

The problem here is that EclipseLink apparently expects the addNamedQuery argument to be its Query implementation type, with a hard downcast. Spring creates proxies for Query instances, expecting them to be used for application purposes.

I suppose we should unwrap Query arguments in our EntityManagerFactory proxy before passing it on to the native EntityManagerFactory. That should cover cases like yours for any kind of persistence provider. I'll try that approach for 4.2.5.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Lukáš Vasek commented

Sounds good. Will wait for fix.

Thanks

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

FWIW, strictly speaking, EclipseLink should actually do such unwrapping itself: Query has a dedicated unwrap method for that purpose. Before downcasting, EclipseLink should actually call unwrap with the type that it intends to downcast to.

It is also worth noting that the problem only occurs with a shared EntityManager as obtained via @PersistenceContext. Using a regular EntityManager created through EntityManagerFactory.createEntityManager(), Spring is not wrapping any Query objects and therefore no downcasting problem should arise in the first place.

In any case, we'll address this in Spring itself to be on the safe side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants