MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » "main" org.hibernate.exception.SQLGram

"main" org.hibernate.exception.SQLGrammarException:

www.MyException.Cn  网友分享于:2013-11-10  浏览:448次
hibernate 查询的一个问题
这是控制台信息
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 query

Caused 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());
}

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

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有