Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830
this week in the
Programmer Certification
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Object Relational Mapping
hibernate error
Amirtharaj Chinnaraj
Ranch Hand
Posts: 242
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi guys iam facing an error
while casting a collection
below shows the code
public Object validateFreeDownloads(String [] freeDownloads) throws Exception { for(int i=0;i<freeDownloads.length;i++) { String temp=freeDownloads[i]; String productTracks[]=temp.split(","); Product p=null; HashSet dbTrackCollections=null; ArrayList trackCollections=null; for(int j=0;i<productTracks.length;i++) { if(j==0) { ProductDAO pDAO=(ProductDAO) getDaoFactory().createDAO("productDAOImplementer"); p=(Product)pDAO.validateProduct(productTracks[0]); if(p==null) {return "failure";} else{} [B]dbTrackCollections=(HashSet)p.getProductTracks();[/B] } if(dbTrackCollections!=null) { trackCollections=(ArrayList)Arrays.asList(productTracks); trackCollections.remove(0); for(Iterator it=dbTrackCollections.iterator();it.hasNext() :wink: { ProductTrack pt=(ProductTrack)it.next(); int TKno=pt.getTrackNumber(); String s=""+TKno; if(trackCollections.contains(s)){} else {return "failure ,"+p.getProductID()+" , "+s;} } } } } return "sucess"; }
below shows the stack trace
[B]java.lang.ClassCastException: org.hibernate.collection.PersistentSet[/B] com.rs.commerce.businessobjects.administrator.BasicAdministratorProcessor.validateFreeDownloads(BasicAdministratorProcessor.java:264) com.softslate.commerce.administrator.core.SettingsAction.execute(SettingsAction.java:52) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) com.softslate.commerce.administrator.core.AdministratorFilter.doFilter(AdministratorFilter.java:44) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) com.softslate.commerce.customer.core.SEOFilter.doFilter(SEOFilter.java:86) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) com.softslate.commerce.customer.core.HibernateFilter.doFilter(HibernateFilter.java:69) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175) org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112) java.lang.Thread.run(Thread.java:595)
Paul Sturrock
Bartender
Posts: 10336
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What kind of Set does getProductTracks() return? What HashSet have you imported into your class? A Hibernare PersistentSet does not extend HashSet, so you can't cast from one to the other.
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
Amirtharaj Chinnaraj
Ranch Hand
Posts: 242
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
getProductTracks() returns Collection
but i have tried with casting ArrayList also iam getting the same error
thanks
amir
[ April 23, 2008: Message edited by: Amirtharaj Chinnaraj ]
Paul Sturrock
Bartender
Posts: 10336
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
So why is dbTrackCollections defined as a HashSet? Chould it not be a Collection too?
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Run a getClass() method call on the object before the cast and see what object type is being returned. It may not be what you expect!
-Cameron McKenzie
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
exception when it reach tiles:insert tag ??
preparedstatement throws sqlexception
DisplayTag & dynamic pagesize
Error while using lookup
Struts error cannot find bean
More...