开发者

New Object in JPQL and selects

开发者 https://www.devze.com 2023-03-19 04:05 出处:网络
Why would a JPQL query Select new Foo(X,Y) from X join X.y as Y Where ... produces more than o开发者_如何学Pythonne sql? 1 for main select and 1 each for X and Y? Let\'s guess. One query that sele

Why would a JPQL query

Select new Foo(X,Y) from X join X.y as Y Where ...

produces more than o开发者_如何学Pythonne sql? 1 for main select and 1 each for X and Y?


Let's guess. One query that selects that IDs of X, Y and then 1 query for X to load its other fields (in the constructor of Foo), and then 1 query for Y to load its other fields (when accessed in the constructor of Foo).

Obviously you could easily do

SELECT new Foo(x.id, x.field2, x.field3, y.id, y.field2) FROM X join X.y as Y ...

and that would (with DataNucleus JPA) do a single SELECT.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号