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;
}
Wenn ich folgend in Haupt laufen:Wie erhalte ich einen automatisch generierten Wert?
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();
Es ist in der Spalte "b" in Tabelle zweiten null gesetzt? Wie kann ich den Wert, der automatisch erstellt wird in a
in First
in b
in Second
setzen?
Kann ich zweite Frage stellen? Was passiert, wenn ich die Second-Tabelle auf ihrem Primärschlüssel "a" statt "b" mit verbinden möchte: @ManyToOne @JoinColumn (name = "a", einfügbar = false, updatable = false) Zuerst zuerst; – Moro