I have the following two classes:
@Entity
class A {
@Id
private aId;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "AB", joinColumns = @JoinColumn(name = "aId", referencedColumnName = "aId"), inverseJoinColumns = @JoinColumn(name = "bId", referencedColumnName = "bId"))
private Set<B> bSet;
}
@Entity
class B {
@Id
private bId;
}
I load the complete structure of the object from one database and then add a new transaction to the second database to save the structure again. However, table "AB" remains empty. This is very strange since "B" is preserved, although I only explicitly save "A". I verify that A-objects contain non-empty sets B, so this is not a problem.
This leaves me with the conclusion that Hibernate believes that an “AB” -table must exist, since both “A” and “B” already have their primary keys. Is there any way around this so that I can get Hibernate to save the connection table in a second database?