I have a relation of type @ManyToMany
with a @JoinTable
association.
The thing is that the entity in the relation has its own table, but a couple of properties should go to the association table.
The A_C
table is fine I think.
Adding the @SecondaryTable
duplicate.
@Entity
@Table(name = "A")
@SecondaryTable(name = "A_C", pkJoinColumns = {
@PrimaryKeyJoinColumn(columnDefinition = "A_ID", name = "A_ID")})
class A {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "A_B", joinColumns = {@JoinColumn(name = "A_ID")}, inverseJoinColumns = {@JoinColumn(name = "B_ID")})
private List<B> bs = new ArrayList<B>();
@Column(table = "A_B")
private int b1;
}
@Entity
@Table(name = "B")
@SecondaryTable(name = "A_B", pkJoinColumns = {
@PrimaryKeyJoinColumn(columnDefinition = "B_ID", name = "B_ID")})
class B {
@Column(table = "A_B")
private int a1;
@Column(table = "A_B")
private int a2;
@ManyToMany(mappedBy = "A_ID", fetch = FetchType.LAZY)
private List<A> as = new ArrayList<A>();
}
This when saving A
entities the B
are duplicated in a way where:
A_ID B_ID a1 a2
1 0 1 1
1 1 0 0
Where should be
A_ID B_ID a1 a2
1 1 1 1
With @Embeddable
won't work neither.
ssedano.