|

楼主 |
发表于 2007-1-24 17:01:48
|
显示全部楼层
public static void main(String[] args) {
// TODO Auto-generated method stub
Session session = HibernateSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
String key="shang";
// Object[] obj;
Account a ;
Hotel h ;
Query query = session.createQuery("select a from Account as a join a.hotel where a.name like '%"+key+"%'");
List list = query.list();
for(int i =0;i<list.size();i++)
{
// h = (Hotel)list.get(i);
a = (Account)list.get(i);
// a = (Account)obj[1];
//h = (Hotel)obj[2];
System.out.println(a.getName()+" ");
}
tx.commit();
HibernateSessionFactory.closeSession();
}
编译通过
public static void main(String[] args) {
// TODO Auto-generated method stub
Session session = HibernateSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
String key="shang";
// Object[] obj;
Account a ;
Hotel h ;
Query query = session.createQuery("select a from Account as a join a.hotel where a.name like '%"+key+"%'");
List list = query.list();
for(int i =0;i<list.size();i++)
{
h = (Hotel)list.get(i);
// a = (Account)list.get(i);
// a = (Account)obj[1];
//h = (Hotel)obj[2];
System.out.println(h.getHotelUid()+" ");
}
tx.commit();
HibernateSessionFactory.closeSession();
}
出现java.lang.ClassCastException异常 |
|