I always use the following method to implement ManyToOne in class :
@Column(name = "buyer_id")
private Long buyerId;
@ManyToOne
@JoinColumn(name = "buyer_id", insertable = false, updatable = false)
UserGroup buyer;
However, I have a question whether it is better to use the following code:
@ManyToOne
@JoinColumn(name = "buyer_id", insertable = false, updatable = false)
UserGroup buyer;
or not? In the first case, I always set the id value obtained in buyerId for saving after saving the UserGroup, but in the second case, I put the userGroup model completely (after save) in my entity then save entity. I'm not sure if the method I use is the best. I searched the internet but could not find a technical reason that the latter is not appropriate.