org.hibernate.QueryException: could not resolve property:xxxxxid 外键查询 hibernate
2016-02-03 15:02
621 查看
转载:http://zhidao.baidu.com/link?url=IqxAQMkf0qRbYNqKKmjLLZ_zSZOQf-RGJ5lmokc04VDLDQJWS1MP14lFnevGB2rCS0WtifXaAAcqRmEqNY8tHq
我有两张表:Teacher id(主键) name Student id(主键) name tid(外键对应Teacher的id) public List findStudentByTeacher(Teacher teacher) { try { session = this.openSession(); String HQL = "select s.name from Student as s where s.tid ="+teacher.getId(); query = session.createQuery(HQL); return query.list(); } catch (Exception e) { e.printStackTrace(); logs.error("查询学生时候出现错误!"); return null; }finally{ this.closeSession(session); } } 调用时出现异常: org.hibernate.QueryException: could not resolve property: tid of: com.accp.hibernate.po.Student [select s.name from com.accp.hibernate.po.Student as s where s.tid =2] at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43) at ... ... 2008-11-04 16:57:10,203 [com.accp.hibernate.dao.BusinessDAOimpt]-[ERROR] 查询学生时候出现错误! 我tid为2的学生有很多 为什么?? 请问要配置什么?还是HQL语句写的有问题?
能改吗? 在那里能改? 是 <many-to-one name="teacher" class="com.accp.hibernate.po.Teacher" fetch="select"> <column name="tid" not-null="true" /> </many-to-one>
改为:String HQL = "select s.name from Student as s where s.teacher.id ="+teacher.getId();
相关文章推荐
- Android 动画 ValueAnimator(二)
- NGUI中实现数字逐步增加
- 新浪微博UWP UI意见征求
- Guest can reach outside network, but cannot reach host when using macvtap interface
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B. Guess the Permutation 水题
- IOS8以上版本,使用UIAlertController代替 UIActionSheet和UIAlertView
- 使用Excel PowerQuery和PowerPivot分析Dynamics CRM数据
- BZOJ 1570: [JSOI2008]Blue Mary的旅行( 二分答案 + 最大流 )
- Android 动画 ValueAnimator(一)
- JMS入门(三)--Queue的使用
- UIGraphicsBeginImageContext和UIGraphicsBeginImageContextWithOptions实现iOS中的截图功能
- UIScrollView 使用AutoLayout布局遇到的问题
- VBA中Dictionary对象使用(Key,Value)
- 7.12 Models -- Frequently Asked Questions
- valueof(), intvalue(0 parseint() 这三个方法怎么用
- 【项目经验】--EasyUI DataGrid之右键菜单
- 【项目经验】--EasyUI DataGrid之右键菜单
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- ionic build android Could not resolve com.android.tools.build:gradle:1.5.0
- SharePoint Server 2016 RC 版本输入Query之后无法返回Search Result的解决方案