Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Created November 11, 2013 00:39
Show Gist options
  • Save volgar1x/7405971 to your computer and use it in GitHub Desktop.
Save volgar1x/7405971 to your computer and use it in GitHub Desktop.
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = Parent.class)
public static class Parent {
private long id;
private String name;
@OneToMany
private List<Child> children = new ArrayList<>();
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 List<Child> getChildren() {
return children;
}
public Parent addChild(Child child) {
this.children.add(child);
return this;
}
public void setChildren(List<Child> children) {
this.children = children;
}
}
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = Child.class)
public static class Child {
private long id;
private String name;
@ManyToOne
private Parent parent;
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 Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment