У меня есть модель данных, которая содержит 3 таблицы: User, Profile, UserProfile.
public class User implements Serializable {
private Integer id;
......
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch =
FetchType.LAZY)
@JsonManagedReference
@JsonProperty("profiles")
private List<UserProfile> userProfiles = new ArrayList<UserProfile>();
}
public class Profile implements Serializable {
private Integer id;
......
@OneToMany(mappedBy="profile", cascade = CascadeType.ALL, fetch =
FetchType.LAZY)
@JsonBackReference
private List<UserProfile> userProfiles= new ArrayList<UserProfile>();
}
public class UserProfile implements Serializable {
private Integer id;
@ManyToOne
@JoinColumn(name = "idUser")
@JsonBackReference
private User user;
@ManyToOne
@JoinColumn(name = "idProfile")
@JsonManagedReference
private Profile profile;
}
И вот моя обратная связь json:
{"id": 1, ....... "profile": [{"profile": {"id": 1, .....}, {"id": 2, .....}}]}
У меня два вопроса: можно ли удалить атрибут профиля и иметь: {"id": 1, ....... "анкеты": [{"id": 1, .....},{": 2, .....}]}
Во многих отношениях с промежуточной таблицей, содержащей первичный ключ (id), 2 внешних ключа, которые являются идентификаторами 2 таблиц, которые имеютмногие отношения, это как это сделать?