Created
April 18, 2012 18:03
-
-
Save maggandalf/2415467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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