I have following
Order {
Date date,
String title,
List<Item> items
}
Item {
String name,
String qty,
... [other non-related information]
}
I can write an HQL which will return me a list of Orders with items in it.
SELECT order
FROM Orders order
LEFT JOIN FETCH oder.items
WHERE item.qty > 2
My question is, can I put Constructor Expression on "Item" to get only (name & qty)?
答案 0 :(得分:0)
不。但是,您可以使用entity graph仅加载您感兴趣的Item
个字段。
请注意:
Item
,id
和name
以外的任何qty
属性,否则hibernate可能会尝试初始化其余的实体属性(将发出数据库查询或将抛出LazyInitializationException
,具体取决于实体状态)。这包括您的应用程序的“不太明显”部分,如JSON序列化库