title: JPA : one table with primary key and another table with primary and foreign key
body: <p>I started studing JPA by reading a book and they gave an unidirection mapping which is like this:</p>
  
  <p>table <strong><em>vehicle</em></strong></p>
  
  <pre><code>(vehicleId, brand, model, dev_year, extraId) 
  </code></pre>
  
  <blockquote>
    <p><strong>vehicleId</strong> is the PK, 
    <strong>extraId</strong> is the FK</p>
  </blockquote>
  
  <p>table <strong><em>travel_extra</em></strong></p>
  
  <p><code>(id, allowSmoke, allowFood, allowDrinks, airConditioner)</code> </p>
  
  <blockquote>
    <p><strong><em>id</em></strong> is the PK</p>
  </blockquote>
  
  <p>Then the java objects: </p>
  
  <pre><code>public class Vehicle {
  
     @Id
     private long vehicleId;
     private String brand;
     private String model;
  
     @OneToOne
     @JoinColumn(name = "vehicleId")
     private TravelExtra travelExtra;
  }
  
  
  public class TravelExtra {
  
       @Id
       private id;
  
       private boolean allowSmoke;
       private boolean allowFood;
       private boolean allowDrinks;
       private boolean airConditioner; 
  
  }
  </code></pre>
  
  <p>When i <em>persist</em> and <em>commit</em> the transaction it works like a charm.</p>
  
  <p>However! for my case i don't want the <strong>vehicle</strong> table to have a foreign key but i want the foreign key to be in the <strong>travel_extra</strong> table and link to the primary key of vehicle table. BUT when i do that the code doesnt work and no matter what i try to do i can not make it work.</p>
  
  <p>If somebody has ever experianced such thing i will be happy for some assitance and examples of how to make it works.</p>
  
  <p>Thanks in advance.</p>