Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  1. In the ORM.xml file, define a named-native-query and specify the SQL statement to be executed.

  2. Define the Projection interface with the required getters for the columns that need to be returned.

  3. Create a ProjectionList by adding Projections to it for each column that needs to be returned.

  4. Use the createNativeQuery method of EntityManager to create a Query object from the named-native-query.

  5. Apply the ProjectionList to the Query object using the setProjection method.

  6. Execute the query using the getResultList method of the Query object.

  7. The results of the query will be returned as a list of Projection objects. Each Projection object will contain the values of the selected columns as returned by the database.