Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
  1. Legen Sie ein Entity Car an und fügen Sie folgende Attribute hinzuCreate a new Car entity and add the following attributes:
    1. registration vom Typ  of type Date 
    2. mileage vom Typ  of type Integer
    3. kw vom Typ  of type Integer
    4. price vom Typ  of type Double
  2. Schließen Sie das Tab Car und klicken Sie im folgenden Dialog auf Yes, um das Entity Car zu speichern.
  3. Legen Sie ein Entity Logbook an.
  4. Klicken Sie im Project Manager bei Entities auf Car.java und fügen Sie das Entity Car in den Entity-Editor bei Attributes ein.
  5. Wählen Sie im folgenden Dialog die Option Close the Car tab and click Yes in the following dialog to save the Car entity
  6. Create a Logbook entity.
  7. Under Entities in the Project Manager, click Car.java and add the Car entity to the entity editor under Attributes.
  8. In the following dialog, choose the One to One (1:1) option
  9. Übernehmen Sie die Einstellung Apply the setting Bidirectional.
  10. Klicken Sie auf OKClick OK.Klicken Sie
  11. auf SpeichernClick Save.


...


Result:
  • Entity Car - Das Entity Car wird um das Attribut logbook vom Typ Logbook erweitertThe Car entity is enhanced by the logbook attribute of type Logbook.

    Image Modified

    Code Block
    languagejava
    themeConfluence
    @OneToOne(mappedBy = "car")
    public Logbook getLogbook() {
    	return logbook;
    }
    
    public void setLogbook(Logbook logbook) {
    	this.logbook = logbook;
    }
  • Entity Logbook - Das Entity Logbook wird um das Attribut car vom Typ Car erweitertThe Logbook entity is enhanced by the car attribute of type Car.


    Code Block
    languagejava
    themeConfluence
    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "car_id")
    public Car getCar() {
    	return car;
    }
    
    public void setCar(Car car) {
    	this.car = car;
    }

...

Note:
  • Relation im Code per Annotation - Im Code wird die Relation in beiden Entities mit Hilfe der Annotation @OneToOne definiert.Um eine 1:1 Relation korrekt zu löschen, müssen Sie die entsprechenden Attribute in beiden Entities löschenIn the code, the relation is defined in both entities with the annotation @OneToOne.
  • To correctly delete a 1:1 relation, you have to delete the corresponding attributes in both entities.