vic
vic

Reputation: 2818

One-to-one relationship: unidirectional

Here is a JDL file:

entity Parent {
    name String required
}

entity Child {
    name String required
}

relationship OneToOne {
    Parent{child} to Child  
}

The one-to-one relationship is unidirectional and a Parent has a reference to its Child, but the Child doesn't have a reference to its Parent. Both the Admin front-end and the DB schema are correct in this regard. The Child entity, however, has a parent attribute shown as the following:

@Entity
@Table(name = "child")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class LeftChild implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    @Column(name = "id")
    private Long id;

    @JsonIgnoreProperties(value = { "child" }, allowSetters = true)
    @OneToOne(fetch = FetchType.LAZY, mappedBy = "child")
    private Parent parent;
 ...
}

The Parent attribute shall not be there, right?

Upvotes: 0

Views: 53

Answers (0)

Related Questions