How to join more tables to the same id (FK)?

Hi Monky,

please understand that this is a forum for questions, but your request seems like you want someone else to do your work. I understand that this kind of mapping is not trivial, but there are many similar questions on the web if you search for “composite many-to-one”. Usually, people ask specific questions because they tried something which didn’t work the way they expect. I will do the work for you this time, but beware that you might not receive answers if your request/question is too broad, like this one. Unless you build up an understanding for the possible mappings (by reading a book or tutorials) you will most likely run into the next issue very soon, so I recommend you first try to get familiar with the possibilities before thinking about your concrete model.

@Entity
public class Table1 {
  @Id
  @GeneratedValue
  Long id;
  String name;
  @OneToMany(mappedBy = "table1")
  Set<Table4> table4s;
}
@Entity
public class Table2 {
  @Id
  @GeneratedValue
  Long id;
  String name;
}
@Entity
public class Table3 {
  @Id
  @GeneratedValue
  Long id;
  String name;
}
@Entity
public class Table4 {
  @EmbeddedId
  Table4Id id;
  @ManyToOne(fetch = LAZY)
  @JoinColumn(name = "id1", insertable = false, updatable = false)
  Table1 table1;
  @ManyToOne(fetch = LAZY)
  @JoinColumn(name = "id_link", insertable = false, updatable = false)
  Table2 table2;
  @ManyToOne(fetch = LAZY)
  @JoinColumn(name = "id_link3")
  Table3 table3;
  String name;
}

@Embeddable
public class Table4Id {
  @Column(name = "id1")
  Long id1;
  @Column(name = "id_link")
  Long idLink;
}