I deal with legacy data base such that some tables joined on primary keys
the following is a simple example:
@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 = "a", insertable = false, updatable = false)
First first;
}
When I run the following main:
public class Persister {
public static void main(String[] args) {
Second aSecond = new Second();
First aFirst = new First();
List<Second> scnds = new ArrayList<Second>();
scnds.add(aSecond);
aFirst.seconds = scnds;
aSecond.first = aFirst;
aEntityManager.getTransaction().begin();
aEntityManager.persist(aFirst);
aEntityManager.getTransaction().commit();
}}
It set 0 in the column "a" in table second?
Thanx