Digital Marketing

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.

Comments

Popular posts from this blog

Make online money from the Internet