这是控制台信息
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());
}
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());
}
解决方案 »
- Object[] entityIds = new Object[](entityId)错误
- 项目在不同电脑跑速度差异怎么这么大? 问题在哪? 在线
- dtree加载的时候很慢
- Hrbernate 一对一的问题
- 急求,js时间控件,不要带日期的!!!!!
- 向各位老师请教:java令牌桶算法的例子....在线等啊!
- 刚看了个sturts的页面,,不理解呀..
- 向各位大虾求教,关于快速排序!
- [100分][等待][Tomcat 5.0 启动错误]
- jsp插入信息的问题?
- 问个HTTP的问题 我想通过java实现登录一个网站 并点击一个投票的连接 求个思路
- Hibernate 多表查询-自定义返回结果的操作
where u.id=h.user_id;
可以了。我在写sql-query 的时候结尾多了一个分号。写oracle习惯了后面多写了个;
谢谢哦