'Get Specified columns from many2one table using hibernate

The diagram shows the many2one relationship between employee and department table.

enter image description here

I need the following resultant values on retrieving the data from employee table.

resultant_object = {
  employee_id : 100,
  employee_name : Test
  department : { department_id : 1001 , 
                department_name : IT }
   }

That is I need to specify only the required columns on many2one record (department_id). How can we achieve with JPA, Java Persistence?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source