I am learning hibernate and trying to understand how to establish the relationship between two entities (OneToOne, OneToMany, ManyToMany). Consider the simple scenario:
User Entity:
@Entity
class User {
@Id
private userId;
private Vehicle vehicle;
// other code
}
Vehicle Entity:
@Entity
public class Vehicle {
@Id
private int vehicleId;
private String desc;
// other code
}
My aim is to specify:
One to Many relationship or One to one relationship between User and Vehicle entities.
I know there are OneToOne , OneToMany annotations, but I not able to understand how is this relationship interpreted? Does it depend in which Entity the other Entity is placed?
For example:
@Entity
class User {
@Id
private userId;
private Vehicle vehicle;
// other code
}
As we can see, I have placed the Vehicle entity inside the User entity and if I use OneToMany annotation on top of Vehicle entity, does it mean 1:M relationship between User -> Vehicle entity.
Can anyone help me understand this?

