I have 3 sql tables:
Account (ID (BIGINT),...)
Card (ID (BIGINT),...)
RelationAccountCard (ACCOUNT (BIGINT), CARD(BIGINT), QUANTITY(int))
One account can have multiple cards, one card can have multiple account
@Data
@Entity
public class Account {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@ManyToMany
@JoinTable(
name = "RELATION_ACCOUNT_CARD",
joinColumns = @JoinColumn(name = "ACCOUNT"),
inverseJoinColumns = @JoinColumn(name = "CARD"))
private Set<Card> cardsOwned = new HashSet<>();
}
@Data
@Entity
public class Card {
@Id
private long id;
@JsonIgnore
@ManyToMany(mappedBy = "cardsOwned")
private java.util.Set<Account> accounts;
}
This code above is working if the field "QUANTITY" in relationAccountCard didn't exist. I would like to make the code works knowing that I added the "QUANTITY" field. I tried for hours yesterday without success, do you have an idea of how to do this?
Basically I need to replace private Set<Card> cardsOwned;
by private Set<RelationAccountCard> relationAccountCards;
but I don't know how to