Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
  1. Legen Sie ein Entity Automaker an und fügen Sie ein Attribut company vom Typ String hinzu. 
  2. Schließen Sie das Tab Automaker und klicken Sie im folgenden Dialog auf Yes, um das Entity Automaker zu speichern.
  3. Legen Sie ein Entity Carmodel an und fügen Sie ein Attribut model vom Typ String hinzu. 
  4. Klicken Sie im Project Manager bei Entities auf Automaker.java und fügen Sie das Entity Automaker in den Entity-Editor bei Attributes ein.
  5. Wählen Sie im folgenden Dialog die Option Create an Automaker entity and add a company attribute of type String
  6. Close the Automaker tab and click Yes in the following dialog to save the Automaker entity.
  7. Create a Carmodel entity and add a model attribute of type String.
  8. Under Entities in the Project Manager, click Automaker.java and add the Automaker entity to the entity editor under Attributes.
  9. In the following dialog, choose the Many to One (n:1) option
  10. Übernehmen Sie die Einstellung BidirectionalApply the Bidirectional setting.
  11. Klicken Sie auf Click OK.Klicken Sie auf 
  12. SpeichernClick Save.

...

Result:
  • Entity Carmodel - Das Entity Carmodel wird um das Attribut automaker vom Typ Automaker erweitertThe Carmodel entity is enhanced by the automaker entity of type Automaker.

    Code Block
    languagejava
    themeConfluence
    @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  By applying the setting Bidirectional, the Automaker entity, too, is enhanced with a list of all car models.

    Code Block
    languagejava
    themeConfluence
    @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;
    }


Hinweis:
  • Relation im Code per Annotation - Im Code wird die Relation mit Hilfe der Annotationen @ManyToOne, bzw. in the code via annotation - In the code, the relation is defined with the annotation @ManyToOne or @OneToMany(mappedBy = "automaker") definiert.
  • Plural - Bei  For 1:n Relationen wandelt RapidClipse den Namen des Entities auf der n-Seite wegen der besseren Lesbarkeit automatisch in Plural um, z.B. carmodels.Relation löschen - Um eine 1:n Relation korrekt zu löschen, müssen Sie die entsprechenden Attribute in beiden Entities löschenrelations, RapidClipse automatically generates a plural name for the entity on the n-side, e.g. carmodels, to improve the readability.
  • Delete relation - To correctly delete a 1:n relation, you have to delete the corresponding attributes in both entities.