Về câu hỏi này, tôi đã kiểm tra Spring Data Rest Ambiguous Association Exception nhưng không thể làm cho nó hoạt động cho tôi.Nghỉ ngơi dữ liệu mùa xuân: Phát hiện nhiều liên kết liên kết với cùng loại quan hệ
Như bạn có thể thấy trong mã bên dưới, tôi đã thêm @RestResource
chú thích với rel
bằng một số giá trị khác.
Tương tự như các câu hỏi trên, yêu cầu POST làm việc, nhưng yêu cầu GET ném ngoại lệ về nhiều liên kết gắn với cùng một loại quan hệ:
"Không thể ghi JSON: Phát hiện nhiều liên kết gắn với cùng loại liên quan ! Chia sẻ liên kết @ org.springframework.data.rest.core.annotation.RestResource (rel = createdBy, xuất khẩu = true, path =, [email protected]iption (value =)) @ javax.persistence.ManyToOne (tùy chọn = true, targetEntity = void, cascade = [], lấy = mong muốn) @ javax.persistence.JoinColumn (referencedColumnName = ASSIGNABLE_ID, nullable = false, độc đáo = false, name = CREATED_BY, có thể cập nhật = true, ColumnDefinition =, [email protected] (name =, value = CONSTRAINT, foreignKeyDefinition =), table =, insertable = true) private com.ag.persistence.domain.PersonEntity com.ag.persistence.domain.TeamEntity.createdBy sử dụng @RestResource! (thông qua chuỗi tham chiếu: org.springframework.hateoas.PagedResources [\ "_ embedded \"] -> java.util.UnmodifiableMap [\ "người \"] -> java.util.ArrayList [0]); ngoại lệ lồng nhau là com.fasterxml.jackson.databind.JsonMappingException: Đã phát hiện nhiều liên kết liên kết có cùng loại quan hệ! Phân định rõ ràng liên kết @ org.springframework.data.rest.core.annotation.RestResource (rel = createdBy, xuất khẩu = true, path =, [email protected]iption (value =)) @ javax.persistence.ManyToOne (không bắt buộc = true, targetEntity = vô hiệu, cascade = [], lấy = mong muốn) @ javax.persistence.JoinColumn (referencedColumnName = ASSIGNABLE_ID, nullable = false, độc đáo = false, tên = CREATED_BY, updatable = true, columnDefinition =, [email protected] (name =, giá trị = CONSTRAINT, foreignKeyDefinition =), table =, insertable = true) private com.ag.persistence.domain.PersonEntity com.ag.persistence.domain.TeamEntity.createdBy u hát @RestResource! (thông qua chuỗi tham chiếu: org.springframework.hateoas.PagedResources [\ "_ embedded \"] -> java.util.UnmodifiableMap [\ "người \"] -> java.util.ArrayList [0]) "
lỗi này có vẻ xảy ra trong lớp này:.
@Entity
@Table(name = "team")
public class TeamEntity extends AssignableEntity {
private String name;
private LocalDateTime createdDate;
private LocalDateTime modifiedDate;
private Collection<MembershipEntity> memberships;
private PersonEntity createdBy;
private PersonEntity modifiedBy;
@Basic
@Column(name = "NAME")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Basic
@Column(name = "CREATED_DATE")
public LocalDateTime getCreatedDate() {
return createdDate;
}
public void setCreatedDate(LocalDateTime createdDate) {
this.createdDate = createdDate;
}
@Basic
@Column(name = "MODIFIED_DATE")
public LocalDateTime getModifiedDate() {
return modifiedDate;
}
public void setModifiedDate(LocalDateTime modifiedDate) {
this.modifiedDate = modifiedDate;
}
@OneToMany(mappedBy = "team")
public Collection<MembershipEntity> getMemberships() {
return memberships;
}
public void setMemberships(Collection<MembershipEntity> memberships) {
this.memberships = memberships;
}
@RestResource(rel = "team_createdBy")
@ManyToOne
@JoinColumn(name = "CREATED_BY", referencedColumnName = "ASSIGNABLE_ID", nullable = false)
public PersonEntity getCreatedBy() {
return createdBy;
}
public void setCreatedBy(PersonEntity createdBy) {
this.createdBy = createdBy;
}
@RestResource(rel = "team_modifiedBy")
@ManyToOne
@JoinColumn(name = "MODIFIED_BY", referencedColumnName = "ASSIGNABLE_ID", nullable = false)
public PersonEntity getModifiedBy() {
return modifiedBy;
}
public void setModifiedBy(PersonEntity modifiedBy) {
this.modifiedBy = modifiedBy;
}
}
Trớ trêu thay, tôi không truy cập vào tài nguyên cụ thể này, tôi cũng có các nguồn lực khác với createdBy
và modifiedBy
- là nó trở thành một trong gây ra vấn đề này
Có thực thể nào khác có thuộc tính 'createdBy' không? Ví dụ 'PersonEntity'? – zeroflagL
Tất cả các thực thể của tôi có bốn trường: '' createdBy'', '' modifiedBy'', '' createdDate'' và '' modifiedDate'' – Chad
Đó có thể là vấn đề. Hãy xem [câu hỏi này] (http://stackoverflow.com/questions/24426644/spring-data-rest-detected-multiple-association-links-with-same-relation-type). Cả 'PersonEntity' trong' TeamEntity' của bạn có thể phơi bày một liên kết 'createdBy'. – zeroflagL