Regarding this question, I checked out Spring Data Rest Ambiguous Association Exception but couldn't get it to work for me.
As you can see in my code below, I added @RestResource
annotation with rel
equal to some other value.
Similar to the question above, POST requests work, but GET requests throw exception about multiple association links with the same relation type:
"Could not write JSON: Detected multiple association links with same relation type! Disambiguate association @org.springframework.data.rest.core.annotation.RestResource(rel=createdBy, exported=true, path=, description=@org.springframework.data.rest.core.annotation.Description(value=)) @javax.persistence.ManyToOne(optional=true, targetEntity=void, cascade=[], fetch=EAGER) @javax.persistence.JoinColumn(referencedColumnName=ASSIGNABLE_ID, nullable=false, unique=false, name=CREATED_BY, updatable=true, columnDefinition=, foreignKey=@javax.persistence.ForeignKey(name=, value=CONSTRAINT, foreignKeyDefinition=), table=, insertable=true) private com.ag.persistence.domain.PersonEntity com.ag.persistence.domain.TeamEntity.createdBy using @RestResource! (through reference chain: org.springframework.hateoas.PagedResources[\"_embedded\"]->java.util.UnmodifiableMap[\"persons\"]->java.util.ArrayList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Detected multiple association links with same relation type! Disambiguate association @org.springframework.data.rest.core.annotation.RestResource(rel=createdBy, exported=true, path=, description=@org.springframework.data.rest.core.annotation.Description(value=)) @javax.persistence.ManyToOne(optional=true, targetEntity=void, cascade=[], fetch=EAGER) @javax.persistence.JoinColumn(referencedColumnName=ASSIGNABLE_ID, nullable=false, unique=false, name=CREATED_BY, updatable=true, columnDefinition=, foreignKey=@javax.persistence.ForeignKey(name=, value=CONSTRAINT, foreignKeyDefinition=), table=, insertable=true) private com.ag.persistence.domain.PersonEntity com.ag.persistence.domain.TeamEntity.createdBy using @RestResource! (through reference chain: org.springframework.hateoas.PagedResources[\"_embedded\"]->java.util.UnmodifiableMap[\"persons\"]->java.util.ArrayList[0])"
The error seems to be happening in this class:
@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;
}
}
Ironically, I am not accessing this specific resource. I also have other resources with createdBy
and modifiedBy
-- is it the one causing this issue?