-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: ClassCastException in find
PostPosted: Wed Mar 03, 2010 11:14 am 
Newbie

Joined: Wed Aug 29, 2007 2:09 pm
Posts: 6
After the select I canĀ“t use the objects in list, if I cast to Subscription or SubscriptionPK class the ClassCastException is thrown, how to fix this?

Code:
List<Subscription> subscriptions =
em.createQuery("select s from Subscription s WHERE s.subscriptionPK.msisdn = :param").
setParameter("param", msisdn).
getResultList();



My entity class:

Code:
@Entity
@Table(name = "SUBSCRIPTION")
public class Subscription implements Serializable {

@EmbeddedId
protected SubscriptionPK subscriptionPK;

@Column(name = "DATE_INI")
private Date dateInit;

...
}


Code:
@Embeddable
public class SubscriptionPK implements Serializable {

@Basic(optional = false)
@Column(name = "id")
private String id;

@Basic(optional = false)
@Column(name = "APP_ID")
private long appId;
...
}


Top
 Profile  
 
 Post subject: Re: ClassCastException in find
PostPosted: Wed Mar 03, 2010 11:24 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Please post the relevant code where the exception is thrown and the first lines of the stacktrace.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: ClassCastException in find
PostPosted: Wed Mar 03, 2010 1:51 pm 
Newbie

Joined: Wed Aug 29, 2007 2:09 pm
Posts: 6
Here's the stack:

the 56 line of ServicesManagerImpl is:
Code:
Subscription subs = (Subscription) subscriptions.get(0);


Code:
java.lang.ClassCastException:iunique.model.Subscription cannot be cast to iunique.model.Subscription
at iunique.service.ServicesManagerImpl.findSubscriptionByMSISDN(ServicesManagerImpl.java:56)
at iunique.service.ServicesManagerImpl.getActiveServices(ServicesManagerImpl.java:97)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:416)
at org.apache.wicket.proxy.$Proxy18.getActiveServices(Unknown Source)
at iunique.web.status.ServiceList.<init>(ServiceList.java:29)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:188)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:89)
at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:305)
at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:320)
at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:234)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)


Top
 Profile  
 
 Post subject: Re: ClassCastException in find
PostPosted: Wed Mar 03, 2010 2:08 pm 
Newbie

Joined: Wed Aug 29, 2007 2:09 pm
Posts: 6
With another frameworks and the same error:

Code:
java.lang.ClassCastException: iunique.repository.Subscription cannot be cast to iunique.repository.Subscription
iunique.services.impl.ServicesManagerImpl.findSubscriptionByMSISDN(ServicesManagerImpl.java:27)
iunique.services.impl.ServicesManagerImpl.getActiveServices(ServicesManagerImpl.java:67)
iunique.web.controller.ActiveServicesController.handleRequest(ActiveServicesController.java:23)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


Top
 Profile  
 
 Post subject: Re: ClassCastException in find
PostPosted: Wed Mar 03, 2010 4:50 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Your exception looks like a classloading problem. I think you have your class Subscription in two different classloaders. How did you package your app? As ear with a war inside it? Take care that your library where Subscription is located is only packaged once.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: ClassCastException in find
PostPosted: Wed Mar 03, 2010 5:02 pm 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
you can load other objects in your application with Hibernate?

it seems a classloader problem (because both classes are iunique.repository.Subscription)...very odd!

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.