日期:2014-05-19  浏览次数:20734 次

求帮忙看看这个HQL语句该怎么写
两张表:一张user表,y一张account表,他们之间是一对多的双向关联,user表有user_id字段为主键,account表有account_id为主键,user_id为外键, 两个表是由对应持久类自动生成的, 我现在要从account表中根据指定的user_id 查询出此user_id的account记录。。
我是这样写的("from Account as a where a.user_id=?",id) 不行,

另外这样写也不行:this.getHibernateTemplate().find("from Account as a where a.user_id in (select u.account.user_id from User as u where u.user_id=?)",id);

一样是提示:could not resolve property:user_id;


注意,持久类中也是user_id,但是运行的时候,出现异常,说could not resolve property: user_id ,

我检查了数据库中的表的字段,account表明明有user_id字段为外键,为什么会提示找不到这个字段??请熟悉的人帮忙看看。。毕设大限将至,感激不尽!

------解决方案--------------------
("from Account a where a.user.id=?",id)
其中user是你Account 这个类里面的一个User对象的属性
------解决方案--------------------
Account 这个对象里面根本就没有user_id这个属性 只有user 然后根据user找id
------解决方案--------------------
应该这么写:
("from Account a where a.user.user_id=?",id)
楼主确定你的Account类中,属性是user_id,而不是user?
那怎么映射的一对多?
------解决方案--------------------
("from Account a where a.user.id=?",id)