Ich habe einen Benutzer mit Behörden (ManyToMany Beziehung):Frühling JPA holen ManyToMany
@Entity
@Table(name = "user")
public class User {
@JsonIgnore
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "user_authority",
joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "user_id")},
inverseJoinColumns = {@JoinColumn(name = "authority_name", referencedColumnName = "name")})
private Set<Authority> authorities = new HashSet<>();
}
@Entity
@Table(name = "authority")
public class Authority implements Serializable {
@Id
@Column(length = 50, nullable = false)
private String name;
}
Liquibase (ohne Benutzer, er hat nur eine ID):
<createTable tableName="authority">
<column name="name" type="varchar(50)">
<constraints primaryKey="true" nullable="false"/>
</column>
</createTable>
<createTable tableName="user_authority">
<column name="user_id" type="bigint">
<constraints nullable="false"/>
</column>
<column name="authority_name" type="varchar(50)">
<constraints nullable="false"/>
</column>
</createTable>
<addPrimaryKey columnNames="user_id, authority_name" tableName="user_authority"/>
...
Ich habe alle Benutzer holen Behörden, das ist ein Name. Zum Beispiel muss ich alle Admins holen (Benutzer, die die Berechtigung 'ROLE_ADMIN' haben).
Ich denke, Ihre JPA-Mapping falsch ist. Sie verwenden ** @ ManyToMany ** -Anmerkungen in einer der Entitäten, aber nicht in der anderen. – ujulu
Dieser Code von JHipster, also denke ich, ist es nicht. – Feeco