Consider the two tables as follows:
Table 1 (id_col, name_col)
Table 2 (uid_col, code_col_1, code_col_2)
where,
id_col is the primary key for Table1
uid_col is the primary key for Table2
and id_col is one to many with code_col_1 and code_col_2
Records may look like this: -
Table1
1, xxx
2, yyy
Table2
11, 1, 2
12, 2, 1
12, 2, 2
What will JPA look like in the following classes?
@Entity
@Table(name = "Table1")
public class T1 {
@OneToMany(targetEntity=T2.class, mappedBy="??????", cascade=CascadeType.ALL)
private List<T2> t2;
}
@Entity
@Table(name = "Table2")
public class T2 {
@ManyToOne
@JoinColumn(name="code_col_1")
private T1 t1;
}
source
share