title: Hibernate - @ManyToOne annotation creates additional column
body: <p>So I am following a tutorial about hibernate as i want to use the framework in an upcoming project. I'm having a problem with the @ManyToOne and @OneToMay annotation and Bidirectional mapping. What i want to do is very basic stuff. I simply want two tables, one reperesenting a user, and the other one representing a vehicle. Now i want the user to be able to have many vehicles and a car should "know" the user it belongs to.</p>
  
  <p>As it seems to be "best practice" to create an extra table that holds the connection between users and and vehicles. I tried to do this with the @JoinTable annotation(see below) but it is not working as i want it to.</p>
  
  <p>To do this, I have coded the following classes:</p>
  
  <p><strong>UserDetails.java</strong></p>
  
  <pre><code>@Entity
  @Table(name="USER_DETAILS")
  public class UserDetails {
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private int userId;
  private String userName;
  private String email;
  @OneToMany()
  @JoinTable(name="USER_VEHICLE", joinColumns=@JoinColumn(name="USER_ID"),
              inverseJoinColumns=@JoinColumn(name="VEHICLE_ID")
  )
  private Collection&lt;Vehicle&gt; vehicle = new ArrayList&lt;Vehicle&gt;();
  
  ...
  getters and setters
  </code></pre>
  
  <p><strong>vehicle.java</strong></p>
  
  <pre><code>@Entity
  public class Vehicle {
  @Id
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private int vehicleId;
  private String vehicleName;
  @ManyToOne  
  private UserDetails user;
  
  ...
  getters and setters
  </code></pre>
  
  <p>And class to test the above:</p>
  
  <p><strong>HibernateTest.Java</strong></p>
  
  <pre><code>public class HibernateTest {
  /**
   * 
   * @param args
   */
  public static void main(String[] args){
  
      UserDetails user1 = new UserDetails();      
      user1.setUserName("testUser1");
      user1.setEmail("testEmail1");
  
  
      Vehicle vehicle1 = new Vehicle();
      vehicle1.setVehicleName("Car");
  
      Vehicle vehicle2 = new Vehicle();
      vehicle2.setVehicleName("Jeep");
  
      user1.getVehicle().add(vehicle1);
      user1.getVehicle().add(vehicle2);
      vehicle1.setUser(user1);
      vehicle2.setUser(user1);    
  
      SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
      Session session = sessionFactory.openSession();
      session.beginTransaction();
      session.save(user1);
      session.save(vehicle1);
      session.save(vehicle2);
      session.getTransaction().commit();
      session.close();
  </code></pre>
  
  <p>When I run this, it executes without any errors or exceptions and it creates the following tables:</p>
  
  <pre><code>USER_DETAILS
  +------+----------+---------+
  |userId|email     |userName |
  +------+----------+---------+
  |1     |testEmail1|testUser1|
  +------+----------+---------+
  
  VEHICLE
  +---------+-----------+-----------+
  |vehicleId|vehicleName|user_userId| &lt;- did not expect this column
  +---------+-----------+-----------+
  |1        |Car        |1          |
  +---------+-----------+-----------+
  |2        |Jeep       |1          |
  +---------+-----------+-----------+
  
  USER_VEHICLE
   +------+----------+
  |USER_ID|VEHICLE_ID|
  +-------+----------+
  |1      |1         |
  +-------+----------+
  |1      |2         |
  +-------+----------+
  </code></pre>
  
  <p>As I understand it, the additional column "user_userId" that was created by hibernate seems to be unnecessary, as the connection between users and vehicles is already represented in the "USER_VEHICLE" table, and I did not intend to have this additional column created.</p>
  
  <p>Is the way I did the bidirectional mapping wrong? And what is the right way to get this to work without the additional column being created?  </p>