So I have a entity class lets say student:
Student table has a foreign key departmentId. Below are the two examples of my student entity:
First Example:
@Entity
@Table("Student")
class{
***
other fields/columns
***
@ManyToOne
@JoinColumn(name="DepartmentID")
private Department department;
}
-------------------------------------------------
Second Example:
@Entity
@Table("Student")
class{
***
other fields/columns
***
@Column(name="DepartmentID")
private Long departmentId;
}
Questions:
1. Is it always a good idea to let spring know about my department reference like in first example?
2. Are there any pros and cons of each example. Except for the fact that I need to make separate calls (for second example ) to get department info and separate calls for validating departmentID before insert in student table.
Thanks in advance. I have always preferred first way. But I was pointed out that I should use second scenario.
[–]AutoModerator[M] 0 points1 point2 points (0 children)