Answer the question
In order to leave comments, you need to log in
Hibernate how to add and display in essence an additional column in the binding ManyToMany table?
Good day, please tell me how to solve this problem correctly:
I have 2 entities
@Entity
@Table(name = "products")
public class Product {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "name")
private String name;
@ManyToOne(cascade = {CascadeType.DETACH,CascadeType.MERGE,CascadeType.REFRESH}, fetch = FetchType.LAZY)
@JoinColumn(name = "category")
private Category category;
@Column(name = "cost")
private Double cost;
//constructor getter setter
}
@Entity
@Table(name = "transactions")
public class Transaction {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH},
fetch = FetchType.LAZY)
@JoinTable(
name = "transactions_products",
joinColumns = @JoinColumn(name = "product_id"),
inverseJoinColumns = @JoinColumn(name = "transaction_id")
)
private List<Product> products;
//constructor getter setter
}
private List<Map<Product, Integer>> products;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question