这是控制台信息
Hibernate: select u.id as id0_0_, u.name as name0_0_, u.password as password0_0_, u.telephone as telephone0_0_, u.username as username0_0_, u.isadmin as isadmin0_0_,h.id as id3_1_, h.type_id as type2_3_1_, h.user_id as user3_3_1_, h.street_id as street4_3_1_, h.title as title3_1_, h.description as descript6_3_1_, h.pubdate as pubdate3_1_, h.price as price3_1_, h.contact as contact3_1_, h.floorage as floorage3_1_ from users u,house h 
where u.id=h.user_id;Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute queryCaused by: java.sql.SQLException: ORA-00911: 无效字符可是我把那个sql语句放到数据库里可以正常查询出来,这个是为什么呢??
User.hbm.xml里的代码
<sql-query name="findUserHouse">
<![CDATA[
select {u.*},{h.*} from users u,house h 
where u.id=h.user_id;
]]>
<return alias="u" class="cn.ansn001.houserent.bean.User"></return>
<return alias="h" class="cn.ansn001.houserent.bean.House"></return>
</sql-query>测试代码
Query query=HibernateUtil.getSession().getNamedQuery("findUserHouse");
List list=query.list();
Iterator it=list.iterator();
while(it.hasNext()){
Object[] obj=(Object[])it.next();
User user=(User)obj[0];
House house=(House)obj[1];
System.out.println(user.getName());
System.out.println(house.getTitle());
}

解决方案 »

  1.   

    你把哪个sql语句放数据库里执行了?贴出来,对比下。
      

  2.   

    select u.id as id0_0_, u.name as name0_0_, u.password as password0_0_, u.telephone as telephone0_0_, u.username as username0_0_, u.isadmin as isadmin0_0_,h.id as id3_1_, h.type_id as type2_3_1_, h.user_id as user3_3_1_, h.street_id as street4_3_1_, h.title as title3_1_, h.description as descript6_3_1_, h.pubdate as pubdate3_1_, h.price as price3_1_, h.contact as contact3_1_, h.floorage as floorage3_1_ from users u,house h  
    where u.id=h.user_id;
    可以了。我在写sql-query 的时候结尾多了一个分号。写oracle习惯了后面多写了个;
    谢谢哦