Entity Carmodel - Das Entity Carmodel wird um das Attribut automaker vom Typ Automaker erweitert.
@ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "automaker_id") public Automaker getAutomaker() { return automaker; } public void setAutomaker(Automaker automaker) { this.automaker = automaker; } |
Entity Automaker - Durch die übernommene Einstellung Bidirectional wird gleichzeitig das Entity Automaker um eine Liste mit allen Carmodels erweitert.
@OneToMany(fetch = FetchType.LAZY, mappedBy = "automaker") public List<Carmodel> getCarmodels() { return carmodels; } public void setCarmodels(List<Carmodel> carmodels) { this.carmodels = carmodels; } public Carmodel addCarmodel(Carmodel carmodel) { getCarmodels().add(carmodel); carmodel.setAutomaker(this); return carmodel; } public Carmodel removeCarmodel(Carmodel carmodel) { getCarmodels().remove(carmodel); carmodel.setAutomaker(null); return carmodel; } |