Ask Your Question
2

What are the steps to restrict the columns returned from an ORM.xml named-native-query using Projection?

asked 2023-02-26 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-08-03 21:00:00 +0000

lalupa gravatar image
  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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-26 11:00:00 +0000

Seen: 7 times

Last updated: Aug 03 '22