1
@TableGenerator(name = "trial", table = "third",
pkColumnName = "a" , valueColumnName = "b", pkColumnValue = "first")
@Entity
public class First{
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "trial")
protected int a;
@OneToMany(mappedBy ="first", cascade = CascadeType.PERSIST)
@JoinColumn(name = "a")
protected List<Second> seconds;
}
@Entity
public class Second{
@Id
protected int a;
@ManyToOne
@JoinColumn(name = "b")
First first;
}
내가 메인에서 다음을 실행합니다 : 그것은 두 번째 테이블의 열을 "B"에서 널 (null)로 설정자동 생성 된 값을 얻으려면 어떻게해야합니까?
Second aSecond = new Second();
aSecond.a = 2;
First aFirst = new First();
List<Second> scnds = new ArrayList<Second>();
scnds.add(aSecond);
aFirst.seconds = scnds;
aEntityManager.getTransaction().begin();
aEntityManager.persist(aFirst);
aEntityManager.getTransaction().commit();
? a
의 First
에 자동으로 생성 된 값을 b
에 Second
으로 설정하려면 어떻게해야합니까?
내가 두 번째 질문을 할 수 있을까요? @ManyToOne @JoinColumn (name = "a", insertable = false, updatable = false) 첫 번째 첫 번째로 두 번째 테이블을 기본 키 "a"대신 "b" – Moro