V
V
Victor2014-12-20 00:36:45
Java
Victor, 2014-12-20 00:36:45

How does @OneToMany-Hibernate binding happen?

The question is this.
There is a User entity

@Entity
@Table(name="USER_DETAILS")
public class UserDetails {
@Id
private int id;
@OneToMany(mappedBy="user")
private Collection<Vehicle> vehicles = new ArrayList();
}

and there is a second entity with which there is a connection
@Entity
public class Vehicle {
@Id
private int id;
@ManyToOne
@JoinColumn(name="USER_ID")
private UserDetails user;
}

It's not clear to me how hibernate determines that it needs to call the getUserId() getter method (I omitted getter's and setter's) to form a foreign key, a relationship.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Pavlov, 2014-12-20
@davinctor

Your UserDetails class has an @Id annotation over the variable, and it defines it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question