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 with JPA 2.0 and Eclipselink throws ClassCastException. [SPR-7247] #11906

Closed
spring-projects-issues opened this issue May 30, 2010 · 4 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 30, 2010

Shashi Kale opened SPR-7247 and commented

Hi,

I am using 3.0.1.RELEASE-A of spring along with Spring DM and am facing a similar issue.
My code goes like

Query q = em.createQuery("SELECT e FROM " + entityClazz.getSimpleName()

  • " e");

I get

Caused by: java.lang.ClassCastException: $Proxy194 cannot be cast to javax.persistence.Query
at $Proxy56.createQuery(Unknown Source)
at com.arisglobal.aglite.dao.GenericCrudDAOImpl.findAll(GenericCrudDAOImpl.java:249)
at java.lang.Thread.run(Thread.java:619)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)

Also,
if I make the method in my DAO transactional it works all fine. It doesn't work only if I make it non transactional.

Thanks and Regards,
Shashi


Affects: 3.0.1

Reference URL: https://jira.springsource.org/browse/SPR-6733?focusedCommentId=54096#action_54096

Issue Links:

Referenced from: commits 882289b

@spring-projects-issues
Copy link
Collaborator Author

Shashi Kale commented

The DAO code is simple with entitymanager injection using PersistenceAnnotationPostProcessor as given below.

protected EntityManager em;

@PersistenceContext(unitName="entityManagerFactory")
public void setEntityManager(EntityManager em) {
	String methodName = "setEntityManager(EntityManager em)";
	logger.entering(methodName);
	this.em = em;
	logger.exiting(methodName);
}

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I guess I found the root of the problem: If an extended vendor interface is not visible in your bundle ClassLoader, we'll exclude that entire interface - even if it derives from javax.persistence.Query, which we're then missing unless it is being implemented separately as well. I've fixed this through introspecting parent interfaces in 3.0.3 now.

This will be available in tonight's 3.0.3 snapshot. Would be great if you could give it an early try...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Shashi Kale commented

Thanks Juergen,

I would like to apply the patch to the 3.0.1.RELEASE-A version and test since we have dependency on many spring bundles and can't change quickly to 3.0.3 Snapshot. I will apply the changes to ClassUtils class and test. Would that be fine?

Regards,
Shashi

@spring-projects-issues
Copy link
Collaborator Author

Shashi Kale commented

Hi Juergen,

I have applied the patch on 3.0.1.RELEASE-A and my use case where the exception was being thrown works fine now. I will keep testing this further and keep posted.

Regards,
Shashi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants