Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting a ClassCastException in hibernate
    text
    copied!<p>I'm writing some code in hibernate where I'm required to update some other table (hall_calendar) before a row is inserted in my table (hall_block_calendar). I have status F, E, M from which only those dates submitted by the form having "F" are to be marked "N". My mapping file for pojo class Hall_calendar.java contains composite key for hall_code and calendar_date and hallbookingcompid in the pojo class.</p> <p>My query is working fine. However, the for loop throws an exception. I would appreciate any inputs on this. </p> <pre><code> public boolean addHallCalendarBlock(Hall_block_calendar hbc, Hall_calendar hc) { //boolean result; Session session=HibernateUtil.getSessionFactory().openSession(); Transaction tx=null; try { tx=session.beginTransaction(); Query q=session.createQuery("from Hall_calendar h where h.hallbookingcompid.calendar_date between'"+hbc.getHall_block_from_date()+"' and '"+hbc.getHall_block_to_date()+"' and hall_availability='F'"); System.out.println("query working: "+q.list()); if(!q.list().isEmpty()) { Hall_calendar upd_obj = new Hall_calendar(); for(Iterator it=q.iterate();it.hasNext();) { Object[] row = (Object[]) it.next(); System.out.println("row[0]: "+(String)row[0]); upd_obj= (Hall_calendar) session.load(Hall_calendar.class, (String)row[0]); upd_obj.setHall_availability("N"); session.save(upd_obj); } session.save(hbc); tx.commit(); } } catch(Exception e) { tx.rollback(); e.printStackTrace(); return false; } finally { session.close(); } return true; } query working: [com.cmc.sibs.vo.Hall_calendar@7e9bed, com.cmc.sibs.vo.Hall_calendar@4d2125, com.cmc.sibs.vo.Hall_calendar@1bb41d7, com.cmc.sibs.vo.Hall_calendar@df9252] java.lang.ClassCastException: com.cmc.sibs.vo.Hall_calendar at com.cmc.sibs.dao.SibsDao.addHallCalendarBlock(SibsDao.java:21861) at com.cmc.sibs.delegates.SibsDelegate.addHallCalendarBlock(SibsDelegate.java:2982) at com.cmc.sibs.servlets.AddHallBlocking.doPost(AddHallBlocking.java:86) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 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:859) 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(Unknown Source) boolean in servlet: false </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload