1

So I've been recently creating a ManyToMany Table with custom attributes in Spring Boot. There are the usual 2 foreign keys in it and extra simple attributes as two Longs. The middle table is getting filled as it should, but how do I also manually/programmically set these values.

My ManyToMany Table looks as following:

@Getter
@Setter
@NoArgsConstructor
@Entity(name = "StudentCourseEntity")
@Table(name = "student_courses")
public class StudentCourses implements Serializable {

    @EmbeddedId
    private StudentCourseId studentCourseId;

    @Column
    private Long level;

    @Column
    private Long position;
}

The @EmbeddedId -> StudentCourseId class just has both foreign keys in it. Is it even possible with this ManyToMany variation of just "overwriting" the auto generated ManyToMany table as I did in the example above?

My Student and Course entities don't have a reference on this StudentCourses class, they still have the @ManyToMany implementation to each other.

I'm looking forward for useful answers, thanks guys!

tstdplt
  • 223
  • 1
  • 8
  • sorry for the unnecessary post; it was pretty easy by just saving the first entity and wait 'till the junction table is filled. then I just created a repository for the junction table and updating the database record with the repo ;) – tstdplt Apr 11 '22 at 11:19

0 Answers0