@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;
}
When I run the following in main:
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();
It set null in the column "b" in table second?
How can I get the value that is auto-created in a
in First
to set in b
in Second
?