I am using a Spring MVC Rest Controller to perform some simple CRUD operations on some entities. I'm am struggling a little with Jackson trying to figure out how to properly implement a @ManyToOne relationship. When Jacskon serializes the "inverse" side of the relationship, it omits the "owning" property. Heres a look at my code:
@Entity
public class Competition {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String nameInUrl;
@ManyToOne(cascade = CascadeType.ALL)
@JsonIdentityReference(alwaysAsId=true)
@JsonBackReference(value="test")
private Sport sport;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNameInUrl() {
return nameInUrl;
}
public void setNameInUrl(String nameInUrl) {
this.nameInUrl = nameInUrl;
}
public Sport getSport() {
return sport;
}
public void setSport(Sport sport) {
this.sport = sport;
}
}
@Entity
public class Sport {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String nameInUrl;
@OneToMany(cascade = CascadeType.ALL, mappedBy="sport")
@JsonManagedReference(value="test")
private Set<Competition> competitions = new HashSet<Competition>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNameInUrl() {
return nameInUrl;
}
public void setNameInUrl(String nameInUrl) {
this.nameInUrl = nameInUrl;
}
public Set<Competition> getCompetitions() {
return competitions;
}
public void setCompetitions(Set<Competition> competitions) {
this.competitions = competitions;
}
}
I would like to ask how I can achieve serializing the Competition entity in its entirety, without omitting the Sport entity?
Thanks, Dave