hi All,
I am using following code for getting distinct question code.
try { Session session = HibernateUtil.currentSession(); Query query = session.createSQLQuery("SELECT distinct level1_code,level1_questions from TBLTEP_CLIENT order by level1_code"); list = query.list(); System.out.println("========= list Size = " + list.size()); Iterator iter = list.iterator(); if (!iter.hasNext()) { System.out.println("No question to display."); } while (iter.hasNext()) { TbltepClient tblTepClientObj = (TbltepClient) iter.next(); String questionCode = tblTepClientObj.getId().getLevel1Code(); String question = tblTepClientObj.getLevel1Questions(); } } catch (Exception e) { e.printStackTrace(); } finally { HibernateUtil.closeSession(); }
but on line TbltepClient tblTepClientObj = (TbltepClient) iter.next(); I am getting typecasting error stating object can not be cast to TbltepClient. I also tried following thing Query query = session.createSQLQuery("SELECT distinct level1_code,level1_questions from TBLTEP_CLIENT order by level1_code").addEntity(TbltepClient.class); here I am also geting error. Please tell me How can I get level1_code and level1_question from object.
|