随笔-112  评论-73  文章-0  trackbacks-0
问题是这样的:
使用DetachedCriteria 查询,当使用多表关联查询时只能通过其他表的主键设置值,非主键进行关联就提示
could not resolve property: XXX of XXX

例如:

c.add(Restrictions.eq("customer.id", customerId));
其中customer是本实体的一个属性,设置关联.id 为customer的主键
这种方式可以进行查询,并得到正确的结果.

c.add(Restrictions.eq("customer.number", number))
这里的number 是customer 的非主键属性,这种方式查询时提示 could not resolve property customer.number of xxx.

经过测试表明,hibernate 应该是不支持这种非主键设置值进行查询。但是使用nameQuery 写语句的方式却是可以查询并得到正确结果.
语句为:
select x from X as x where customer.number =?

谁能合解释一下呢?为什么呢?

posted on 2010-04-28 22:44 Libo 阅读(282) 评论(0)  编辑  收藏 所属分类: 其他

只有注册用户登录后才能发表评论。


网站导航: