| Hi,I have the following two classes: Student and Department.
 
 class Student {
 @Id
 public void getId() {
 ...
 }
 
 ...
 @ManyToOne(optional = false)
 @JoinColumn(name = "DEPT_ID")
 public Department getDepartment() {
 return this._department;
 }
 
 private Long _id;
 private Department _department;
 }
 
 All this works fine. But the problem is that my foreign key, getDepartment has to return a Department object. I was wondering if this can be made to return a Long (which is the id of the department row concerned). The reason I was this is that I do not want to read in the entire department column (avoid a join of the user with the department table).
 
 This problem becomes worse if the getDepartment is a set. Any set operation that requires equals/hashCode which I currently override to do business key based equality/ But any set operation leads to loading of all the department objects unnecessarily. I need to have this as a Set and not a bag.
 
 Thanks,
 
 
 |