title: Hibernate - from Annotations to XML Configuration files
body: <p>I used Hibernate Annotations for mapping tables, but I wanted move to xml mapping files (*hbm.xml), and I have some troubles. I have 4 tables (users, cars, rentals, user_car) and 3 classes (User, Car, Rental)</p>
  
  <p>User </p>
  
  <pre><code>@Entity
  @Table(name = "USERS")
  @SuppressWarnings("serial")
  public class User implements Serializable {
  
    private Long id;
    private List&lt;Car&gt; cars;
  
    @Id
    @GeneratedValue
    @Column(name = "ID")
    public Long getId() {
        return id;
    }
    @OneToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "USER_CAR", joinColumns = { @JoinColumn(name = "CAR_ID") },   inverseJoinColumns = { @JoinColumn(name = "USER_ID", referencedColumnName = "ID") })
    public List&lt;Car&gt; getCars() {
        return cars;
    }
   ...
  }
  </code></pre>
  
  <p>Car</p>
  
  <pre><code>@Entity
  @Table(name = "CARS")
  @SuppressWarnings("serial")
  public class Car implements Serializable {
  
    private Long id;
    private User owner;
  
    @Id
    @GeneratedValue
    @Column(name = "ID")
    public Long getId() {
        return id;
    }
    @OneToOne(cascade = CascadeType.ALL)
    @JoinTable(name = "USER_CAR", joinColumns = { @JoinColumn(name = "CAR_ID", referencedColumnName = "ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID") })
    public User getOwner() {
        return owner;
    }
  ...
  }
  </code></pre>
  
  <p>Rental</p>
  
  <pre><code>@Entity
  @Table(name = "RENTALS")
  @SuppressWarnings("serial")
  public class Rental implements Serializable {
  
    private Long id;
    private Car car;
    private User user;
    private Date date;
  
    @Id
    @GeneratedValue
    @Column(name = "ID")
    public Long getId() {
        return id;
    }
    @ManyToOne
    @JoinColumn(name = "CAR_ID")
    public Car getCar() {
        return car;
    }
    @ManyToOne
    @JoinColumn(name = "USER_ID")
    public User getUser() {
        return user;
    }
    @Column(name = "RENT_DATE", nullable=false)
    @Temporal(TemporalType.DATE)
    public Date getDate() {
        return date;
    }
  ...
  }
  </code></pre>
  
  <p>Eclipse generated mapping files, and I've made some improvements</p>
  
  <p>Car</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="com.bontade.mvc.models.Car" table="CARS"&gt;
      &lt;id name="id" type="java.lang.Long"&gt;
          &lt;column name="ID" /&gt;
          &lt;generator class="assigned" /&gt;
      &lt;/id&gt;
      &lt;many-to-one name="owner" class="com.bontade.mvc.models.User" fetch="join"&gt;
          &lt;column name="USER_CAR" /&gt;
      &lt;/many-to-one&gt;
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>User</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="com.bontade.mvc.models.User" table="USERS"&gt;
      &lt;id name="id" type="java.lang.Long"&gt;
          &lt;column name="ID" /&gt;
          &lt;generator class="assigned" /&gt;
      &lt;/id&gt;
      &lt;property name="name" not-null="true" length="100" type="java.lang.String"&gt;
          &lt;column name="NAME" /&gt;
      &lt;/property&gt;
      &lt;list name="cars" inverse="false" table="CAR" lazy="true"&gt;
          &lt;key&gt;
              &lt;column name="ID" /&gt;
          &lt;/key&gt;
          &lt;list-index&gt;&lt;/list-index&gt;
          &lt;one-to-many class="com.bontade.mvc.models.Car" /&gt;
      &lt;/list&gt;
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Rental</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="com.bontade.mvc.models.Rental" table="RENTALS"&gt;
      &lt;id name="id" type="java.lang.Long"&gt;
          &lt;column name="ID" /&gt;
          &lt;generator class="assigned" /&gt;
      &lt;/id&gt;
      &lt;many-to-one name="car" class="com.bontade.mvc.models.Car" fetch="join"&gt;
          &lt;column name="CAR_ID" /&gt;
      &lt;/many-to-one&gt;
      &lt;many-to-one name="user" class="com.bontade.mvc.models.User" fetch="join"&gt;
          &lt;column name="USER_ID" /&gt;
      &lt;/many-to-one&gt;
      &lt;property name="date" type="java.util.Date"&gt;
          &lt;column name="RENT_DATE" /&gt;
      &lt;/property&gt;
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>But, I don't know how can I declare and connect "proxy" table USER_CAR.</p>