[ACCEPTED]-Hibernate: How to Join three 3 tables in one join table in Annotation?-jointable
Accepted answer
The problem is that you have defined a relationship 8 to roles and a separate relationship to applications. There's 7 no declaration that any specific user is 6 a join of both one role and one application.
When 5 you try to associate with a role, the application 4 is null and visa-versa.
Here's an example 3 of mapping a 3-way join between classes 2 A
, B
and C
using JPA. Note, no entity is required 1 for the join table.
@Entity
public class A {
@JoinTable(name = "a_b_c",
joinColumns = @JoinColumn(name = "a_id"),
inverseJoinColumns = @JoinColumn(name = "c_id"))
@MapKeyJoinColumn(name = "b_id")
@ElementCollection
private Map<B, C> cByB = new HashMap<>();
}
@Entity
public class B {
...
}
@Entity
public class C {
...
}
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.