I have a relationship like @ManyToMany
with the association @JoinTable
.
The fact is that an object in relation has its own table, but a couple of properties should go to the association table.
Table A_C
is fine, I think.
Adding a duplicate of @SecondaryTable
.
@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 while maintaining A
entities B
duplicated in such 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
will not work either.
ssedano.
source share