com.one2many.Author objAuthorRs = null;
com.one2many.Author objAuthorERROR = null;
String strQueryString = "select p from com.one2many.Author as p where p.AUTHORID like :ID";
net.sf.hibernate.Query objQuery = objSession.createQuery(strQueryString);
objQuery.setString("ID","111");
//java.util.Iterator objIteratorRs = objQuery.iterate();
//while(objIteratorRs.hasNext())
//{
// objAuthorRs = (com.one2many.Author)objIteratorRs.next();
// System.out.println(objAuthorRs.getALIAS());
//}
for(java.util.Iterator objIteratorRs = objQuery.iterate();objIteratorRs.hasNext();)
{
objAuthorRs =(com.one2many.Author)objIteratorRs.next();
//objAuthorRs =(com.one2many.Author)objQuery.list().get(0);
System.out.println(objAuthorRs.getALIAS());
}
//strQueryString = "select a.AUTHORID,a.ALIAS from com.one2many.Author AS a WHERE a.AUTHORID LIKE :ID";
strQueryString = "select a.AUTHORID from com.one2many.Author as a where a.AUTHORID like :AUTHORID";
net.sf.hibernate.Query objQueryERROR= objSession.createQuery(strQueryString);
//objQuery = objSession.createQuery(strQueryString);
objQueryERROR.setString("AUTHORID","111");
for(java.util.Iterator objIteratorERROR = objQueryERROR.iterate();objIteratorERROR.hasNext();)
{
objAuthorERROR =(com.one2many.Author)objIteratorERROR.next();
//objAuthorRs =(com.one2many.Author)objQuery.list().get(0);
System.out.println(objAuthorERROR.getALIAS());
}
the first select runs ok,but the second can't runs...,i don't know why?
the second throw the error:
java.lang.ClassCastException
at com.one2many.hibernateselect.main(hibernateselect.java:106)
thanks a lot!
|