what is @JoinColumn and how it is used in Hibernate
<p>I have been reading a lot about @JoinColumn but I still don't get the idea behind it.</p>

<p>Patient Table</p>

<pre><code>CREATE TABLE patient (
patient_id BIGINT NOT NULL,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
PRIMARY KEY(patient_id));
</code></pre>

<p>Vehicle Table</p>

<pre><code>CREATE TABLE vehicles (
patient_id BIGINT NOT NULL,
vehicle_id BIGINT NOT NULL,
vehicle_manufacturer VARCHAR(255),
PRIMARY KEY (vehicle_id),
CONSTRAINT patienthasmanyvehicle FOREIGN KEY(patient_id) REFERENCES patient(patient_id));
</code></pre>

<p>Patient Class</p>

<pre><code>@OneToMany(mappedBy = "patient")
    private Collection&lt;Vehicle&gt; patientVehicles = new ArrayList&lt;Vehicle&gt;();
</code></pre>

<p>Vehicle Class</p>

<pre><code>@ManyToOne
@JoinColumn(name="patient_id")
private Patient patient;
</code></pre>

<p>I'm confused on how the Vehicle class part, what is the relationship between </p>

<pre><code>Vehicle Class ---- Entity
@JoinColumn(name="patient_id") ---- annotation
private Patient patient ----field
</code></pre>

<p>Does it say; The <strong>Vehicle Entity</strong> has a <strong>Foreign Key</strong> to <strong>Patient entity</strong> named <strong>patient_id</strong>. 
Add the <strong>patient_id</strong> as a column in the <strong>Vehicle Entity table</strong></p>

<p>Do the name parameter of the JoinColumn should always be a <strong>Foreign Key or Primary Key?</strong></p>

<p>I have been reading this but I'm still confuse.
<a href="https://stackoverflow.com/questions/11938253/jpa-joincolumn-vs-mappedby">JPA JoinColumn vs mappedBy</a></p>