Note that there are some explanatory texts on larger screens.

plurals
  1. POparent child relationship implementation
    primarykey
    data
    text
    <p>I'm trying to implement the following <img src="https://i.stack.imgur.com/pU4Rh.png" alt="enter image description here"></p> <p>1 appointment can have 0 to many subAppointments</p> <p>a subAppointment has 1 parent Appointment</p> <p>here is what I've tried:</p> <pre><code>private Appointment parentAppointment; @ManyToMany(cascade = CascadeType.ALL ) private List&lt;Appointment&gt; childrenAppointments; </code></pre> <p>i've also tried some JoinColumn annotations, but it didn't work.</p> <hr> <p>Edit:</p> <p>I've tried Pace's solution -></p> <pre><code>@ManyToOne private Appointment parentAppointment; @OneToMany(cascade = CascadeType.ALL, mappedBy="parentAppointment") private List&lt;Appointment&gt; childrenAppointments; </code></pre> <p>now I've got this error: <code>ERROR: column "appointment_id" appears twice in primary key constraint</code></p> <p>it(Play! Framework) tries to create a table with this script:</p> <pre><code>create table appointment_appointment ( appointment_id integer not null, appointment_id integer not null, constraint pk_appointment_appointment primary key (appointment_id, appointment_id)) ; </code></pre> <hr> <p>Edit2:</p> <p>Fixed by:</p> <pre><code> @ManyToOne @JoinColumn(name = "parent_appointment") private Appointment parentAppointment; @OneToMany( mappedBy="parentAppointment", cascade = CascadeType.ALL) private List&lt;Appointment&gt; childrenAppointments; </code></pre> <p>and </p> <pre><code> public void setParentAppointment(Appointment ap){ this.parentAppointment = ap; } public void addChildAppointment(Appointment ap){ this.childrenAppointments.add(ap); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload