Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Incomplete
-
Affects Version/s: 1.6.3
-
Fix Version/s: None
-
Component/s: class generator
-
Labels:None
-
Number of attachments :
Description
In a Hibernate query we are eager fetching associated objects and the query is returning real domain objects, not proxies. The Domain objects are Groovy objects. When we try to retreive those objects through the Groovy object, the method is trying to cast the real Domain object into a CGLib proxy object, which then throws a ClassCastException.
Caused by: java.lang.ClassCastException: com.pictage.core.client.event.domain.Photo cannot be cast to com.pictage.core.client.event.domain.Photo$$EnhancerByCGLIB$$cce71414
at com.pictage.core.client.event.domain.Photo$$EnhancerByCGLIB$$cce71414$getAccess.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
at com.pictage.core.client.event.domain.Event.setPhotosFromEventPhotosList(Event.groovy:514)
at com.pictage.core.client.event.service.EventServiceImpl.getPersistedEvent(EventServiceImpl.java:509)
at com.pictage.core.client.event.service.EventServiceImpl.getEvent(EventServiceImpl.java:549)
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.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy50.getEvent(Unknown Source)
at com.pictage.client.web.interceptor.EventInterceptor.preHandle(EventInterceptor.java:47)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:753)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:709)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:613)
... 15 more
I tried accessing the property directory and also through a call to getter method and both have the same results
Event.groovy
for (Photo photo: getEventPhotos()) {
versus
for (Photo photo : eventPhotos) {
the Photo object is also a Groovy object Photo.groovy.
New update. Hibernate can be taken out of the equation. We have a sample where we get the same error and we are not using any Hibernate, just plain Java.
The exception also occurs in the following code
The line
in the TrayPhoto constructor is where the ClassCastException is occuring.
Here is the decompiled code of the TrayPhoto constructor