Entity Carmodel - The Carmodel entity is enhanced by the automaker entity of type Automaker.
@ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "automaker_id") public Automaker getAutomaker() { return automaker; } public void setAutomaker(Automaker automaker) { this.automaker = automaker; } |
Entity Automaker - By applying the setting Bidirectional, the Automaker entity, too, is enhanced with a list of all car models.
@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; } |