当前位置: 代码迷 >> Java Web开发 >> "main" org.hibernate.exception.SQLGrammarException:
  详细解决方案

"main" org.hibernate.exception.SQLGrammarException:

热度:361   发布时间:2016-04-17 17:22:35.0
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语句放数据库里执行了?贴出来,对比下。
  相关解决方案