2 Replies Latest reply on Feb 7, 2006 11:33 AM by Chris Malan

    Many to many plus additional value

    Chris Malan Novice

      This question has been asked at least twice. The answer is: "use an intermediate entity to represent your assoc table"

      I looked but could not find much on this in the Hibernate documentation. It is most likely where I did not look.

      I have an idea of what to do, but do not know if it right.

      Take the JBoss Flights_Customers example. Say I want to add another column named Date to the join table.

      Do I do this:

      @Entity
      public class Flights_Customers{
       private String flight, customer;
       private java.sql.Date date;
      

      and then in Flight
      @JoinTable(
       table=@Table(name="Flights_Customers"),
       joinColumns={@JoinColumn(name="flight")},
       inverseJoinColumns={@JoinColumn(name="customer")}
      

      In Customer the joinColumns and inverseJoinColumns swap over. I use a few more annotations to set up the join, but this is what is relevant.

      Is this how it should be done? If not, what should be done differently?

      Thanks,