Fixed problem with infinite recursion on entities by adding @JsonBackReference et al

This commit is contained in:
Jon Brisbin
2012-09-27 15:49:11 -05:00
committed by Jon Brisbin
parent 2ddf788350
commit 4fc50526a3
3 changed files with 11 additions and 2 deletions

View File

@@ -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() {

View File

@@ -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;

View File

@@ -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;