문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top