I have a many-to-many relationship :
customer, product, customer_product with extra column quantity
i want to map them with hibernate my question is :
what i will loose if i just map them normally like two one-to-many ?
customer_product will have just one primary key (id_customer_product) and not a composite primary key (id_product + id_customer)
customer Entity:
@Entity
@Table(name = "customer", catalog = "XX")
public class Customer implements java.io.Serializable {
@OneToMany(fetch = FetchType.LAZY, mappedBy = "customer")
private Set customer_product = new HashSet<Customer_Product>(0);
}
product Entity:
@Entity
@Table(name = "product", catalog = "XX")
public class Customer implements java.io.Serializable {
@OneToMany(fetch = FetchType.LAZY, mappedBy = "product")
private Set customer_product = new HashSet<customer_product>(0);
}
customer_product Entity:
@Entity
@Table(name = "customer_product", catalog = "XX")
public class Customer_Product implements java.io.Serializable {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ID_customer_product")
private Integer ID_customer_product;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_customer")
private Customer customer;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_product")
private Product product;
}
Or i have to make like this answer and make a composite primary key.