Skip to content

Instantly share code, notes, and snippets.

@maggandalf
Created April 18, 2012 18:03
Show Gist options
  • Save maggandalf/2415467 to your computer and use it in GitHub Desktop.
Save maggandalf/2415467 to your computer and use it in GitHub Desktop.
@Entity
public class Starship {
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
private Long id;
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
@OneToMany(mappedBy="starship", cascade={CascadeType.ALL})
private List<Officer> officers = new ArrayList<Officer>();
public List<Officer> getOfficers() {return Collections.unmodifiableList(officers);}
protected void setOfficers(List<Officer> officers) {this.officers = officers;}
public void addOfficer(Officer officer) {
officer.setStarship(this);
this.officers.add(officer);
}
//more code
}
@Entity
public class Officer {
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
private Long id;
public Long getId() {return id;}
protected void setId(Long id) {this.id = id;}
@ManyToOne private Starship starship;
public Starship getStarship() {return starship;}
protected void setStarship(Starship starship) {this.starship = starship;}
//more code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment