Question

I referred to the below one for adding a specific columns to be returned in hibernate. How to return an entity with chosen columns using Criteria

However in mycase the exclusion is small so i would like to see if i can give the list of columns to be excluded in the result.

Is there a optimal way to do it in hibernate?

Was it helpful?

Solution

Note: There is no way to provide exclusions in Hibernate Criteria.

Several other ways of inclusions are below. It is totally your choice.

  1. One way of doing this is creating a light weight hibernate mapping object with only columns that are required.
  2. Use HQL to get the columns that you need like this ' Select c.col1,c.col2 from Columns c'
  3. Construct HQL at run time, have a template prepared like below

    'Select ' + userDefColumns + ' from Columns c'; // pass the userDefColumns at run time.

  4. As mentioned here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top