Bidirectional one-to-many with one as owning side

Viewed 2842

Is there no way of making the 'one' the owner side of a one-to-many relationship? Every single sample has mappedBy in @OneToMany. Even the answer to this similar question has that.

I want the one side to be the owning side because when I add a many/child, I also change some information on the one/parent, and I want just to update the parent, for code simplicity and to ensure that it all goes in the same ACID transaction.

But I just can't make it work. Hibernate keeps complaining about

Repeated column in mapping for entity

My entities:

public class Parent {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @OneToMany(fetch = EAGER, cascade = {ALL}, orphanRemoval = true)
    @JoinColumn(name = "parent_id", referencedColumnName = "id", nullable = false)
    private final Set<Child> children = new HashSet<>();

}

public class Child {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ManyToOne
    private Parent parent;

}
2 Answers
Related