問題是這樣的:
使用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 閱讀(293)
評論(0) 編輯 收藏 所屬分類:
其他