I'm not familiar with Hibernate, and I saw this piece of code in a new project today:
public abstract class ValidationCode {
@Column(name = "userId", updatable = false, insertable = false)
@Getter
@Setter
private long userId;
@ManyToOne
@JoinColumn(name = "userId", referencedColumnName = "userId")
@Getter
@Setter
private MasterUser user;
// ....
}
My question is that is it redundant to declare userId field like this? Can we not just use a getter?
Or maybe it values when in some cases like if we set the fetch type of user to be Lazy, we could access the userId field without fetching the user entity?
What would you suggest?