aiyust070
aiyust070
2011-11-04 11:57

请教个关于hibernate中转化成EntityMode.DOM4J的问题

  • hibernate

请教个问题,关于hibernate的

[code="java"]
public void getXmlCom(){

    Document doc = DocumentHelper.createDocument(); 

    //Element rootElement = doc.addElement("root");


    Session session = (Session) HibernateSessionFactory.getSession();
    //Session session = factory.openSession();
    Session dom4jSession = (Session) session.getSession(EntityMode.DOM4J);
    Transaction tx = session.beginTransaction();

    List results = dom4jSession
        .createQuery(" select m.f1,s.f2 from table1 m ,table2 s  where m.id=s.id and rownum < ? ")
        .setInteger(0 , 2)
        .list();
    for ( int i=0; i<results.size(); i++ ) {
        //add the customer data to the XML document
        Element customer = (Element) results.get(i);
        //rootElement.add(customer);
        doc.add(customer);
    }
    System.out.println(doc.asXML());
    tx.commit();
    session.close();
}

[/code]

这种情况下会出问题:如果把hql改成(select m.f1 from table1 m where rownum < ?)就没问题,怎么解释?
出错的行为:[code="java"]Element customer = (Element) results.get(i);[/code]

并不是说执行语句有问题
谁能解释下,谢谢各位

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答