Skip to content

Possible typo in lesson S3-M3-L2 #184

@evil-face

Description

@evil-face

Hi there, I wanted to know if there was a typo in lesson about One-to-one relationships.

I'm talking about mappedBy="customerId". Isn't it supposed to be simply "customer" in this case?

@Entity
public class Customer {
     // ...
    @OneToOne(mappedBy="customerId")
    private Address address;
    // ...
}

@Entity
public class Address {
    @Id
    private Long id;
    
    private String description;
    
    @OneToOne
    private Customer customer;
    // ...
}

UPD:
Same in Many-to-many relationships:

@Entity
public class Order {
    @Id
    private Long id;
    
    private Date date;
    
    Decimal amount; // btw, BigDecimal?
    
    @ManyToMany
    @JoinTable(name="ORDER_ITEM",
        joinColumns=@JoinColumn(name="ORDER_ID"),
        inverseJoinColumns=@JoinColumn(name="ITEM_ID"))
    private Set<Item> items = new HashSet<>();
    // ...
}

@Entity
public class Item {
    @Id
    @GeneratedValue
    private Long id;
    
    private String name;
    
    @ManyToMany(mappedBy = "orders") // should be "items"?
    private Set<Order> orders = new HashSet<>();
    // ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions