Fixed problem with infinite recursion on entities by adding @JsonBackReference et al
This commit is contained in:
@@ -6,6 +6,8 @@ import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import org.codehaus.jackson.annotate.JsonBackReference;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
@@ -17,7 +19,8 @@ public class Address {
|
||||
private String city;
|
||||
private String province;
|
||||
private String postalCode;
|
||||
@ManyToOne(optional = false, cascade = CascadeType.REMOVE)
|
||||
@JsonBackReference
|
||||
@ManyToOne(optional = false, cascade = CascadeType.REFRESH)
|
||||
private Person person;
|
||||
|
||||
public Address() {
|
||||
|
||||
@@ -6,10 +6,11 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import org.codehaus.jackson.annotate.JsonManagedReference;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
@@ -20,8 +21,10 @@ public class Person {
|
||||
private String name;
|
||||
@Version
|
||||
private Long version;
|
||||
@JsonManagedReference
|
||||
@OneToMany
|
||||
private List<Address> addresses;
|
||||
@JsonManagedReference
|
||||
@OneToMany
|
||||
@MapKey(name = "type")
|
||||
private Map<String, Profile> profiles;
|
||||
|
||||
@@ -5,6 +5,8 @@ import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import org.codehaus.jackson.annotate.JsonBackReference;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
@@ -14,6 +16,7 @@ public class Profile {
|
||||
@Id @GeneratedValue private Long id;
|
||||
private String type;
|
||||
private String url;
|
||||
@JsonBackReference
|
||||
@ManyToOne
|
||||
private Person person;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user