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;
}
Quand je lance ce qui suit dans principal:Comment obtenir une valeur générée automatiquement?
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();
Il ensemble vide dans la colonne « b » dans le tableau seconde? Comment puis-je obtenir la valeur qui est créée automatiquement dans a
dans First
pour définir b
dans Second
?
Puis-je poser la deuxième question? Que faire si je veux rejoindre la deuxième table sur sa clé primaire "a" au lieu de "b" avec: @ManyToOne @JoinColumn (name = "a", insérable = false, updatable = false) Premier en premier; – Moro