anergy
anergy

Reputation: 1384

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 one sql? 1 for main select and 1 each for X and Y?

Upvotes: 0

Views: 339

Answers (1)

DataNucleus
DataNucleus

Reputation: 15577

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.

Upvotes: 3

Related Questions