title: JPA: Foreign key that is also a primary key mapping
body: <p>I have been trying to solve this for whole day but no luck! Also i tried to read most of the tutorials on the net but as you all know they all are full of useless examples that do not reflect what you need in the real world.</p>
  
  <p>So here is my situation:</p>
  
  <p>The database:</p>
  
  <p>table: <strong>vehicles</strong>(vehicleId, brand, model, devYear, regNumber) &lt;-- vehicleId is the PrimaryKey</p>
  
  <p>table: <strong>extras</strong>(vehicleId, allowSmoke, allowFood, allowDrinks, airConditioner) &lt;-- vehicleId is a PK and a FK.</p>
  
  <p>The point is that if i have a class <strong>Vehicle</strong> and a class <strong>TravelExtras</strong> which are mapped to the database i want the <strong>Vehicle</strong> class to have an attribute <strong>TravelExtras</strong> travelExtras and get and set methods.</p>
  
  <p>Unfortunatelly no matter what i tried when i try to persist the object in the databse i get various errors.</p>
  
  <p>Here is an illustration:</p>
  
  <pre><code>        EntityManagerFactory emfactory = Persistence.createEntityManagerFactory( "NaStopPU" );
          EntityManager entitymanager = emfactory.createEntityManager( );
          entitymanager.getTransaction( ).begin( );
  
  
          TravelExtra travelExtra = new TravelExtra();
  
  
          entitymanager.persist(travelExtra);
  
  
          Vehicle vehicle = new Vehicle(2L, "10152487958556242", "Mazda", "626", "334343", 2005, 4);  
          vehicle.setTravelExtra(travelExtra);
  
          entitymanager.persist(vehicle);
  
  
  
          entitymanager.getTransaction().commit();
          entitymanager.close( );
  
          emfactory.close( );
  </code></pre>
  
  <p>Any one knows what kind of annotations to use for this One to one case ?</p>