Oct 30, 2017

Create new Object In JPQL Select Statement by Constructor Expression

When you want to retrieve a Data Transfer Object instead of retrieving a full entity or a full graph of objects in a type safe way, then you can create the new Object in the JPQL select statement:
 SELECT NEW ca.i88.it.UserModel(u.name, u.phone) FROM User u;
Here a constructor is used in the SELECT list to return one or more Java instances. The constructor name must be fully qualified.

Featured Post

Blockchain could solve accounting problems and bring an unprecedented level of accuracy, security, and speed to record-keeping.

By adopting it, companies could eliminate supply chain inefficiencies -- and save billions of dollars.