New Object in JPQL and selects
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.
精彩评论