title: OneToMany Spring Data JDBC
body: <p>I want to model a OneToMany Relation with Spring Data JDBC. I´ve read on this very useful blog <a href="https://spring.io/blog/2018/09/24/spring-data-jdbc-references-and-aggregates" rel="noreferrer">https://spring.io/blog/2018/09/24/spring-data-jdbc-references-and-aggregates</a> that you should use references when you want to model ToMany Reference:  </p>
  
  <blockquote>
    <p>Therefore any Many-to-One and Many-to-Many relationship must be modeled by just referencing the id.</p>
  </blockquote>
  
  <p>So I have this scenario:<br>
  One <code>Student</code> can have multiple <code>Registration</code>. And one <code>Registration</code> can have exactly one <code>Student</code>. If you delete <code>Registration</code> the assigned <code>Student</code> should not get deleted cascading.<br>
  I ended up with this modelling:  </p>
  
  <pre><code>@Data
  @AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@PersistenceConstructor))
  public class Registration {
  
      private final @Id
      @Wither
      long registrationId;
  
      @NotNull
      private String electiveType;
  
      @NotNull
      private LocalDateTime created = LocalDateTime.now();
  
      @NotNull
      private StudentRegistrationReference studentRegistrationReference;
  
  }
  
  @Data
  @AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@PersistenceConstructor))
  public class StudentRegistrationReference {
      private long student;
      private long registration;
  }
  
  @Data
  @AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@PersistenceConstructor))
  public class Student {
  
      private final @Id
      @Wither
      long studentId;
  
      @NotNull
      @Size(min = 4, max = 20)
      private String userId;
  
      @NotNull
      @Min(0)
      private int matriculationNumber;
  
      @NotNull
      @Email
      private String eMail;
  
      private Set&lt;StudentRegistrationReference&gt; studentRegistrationReferences = new HashSet&lt;&gt;();
  
  }
  </code></pre>
  
  <p>My question is whether my modeling is correctly implemented?  </p>