Hi,
Could you please help me with a issue regarding OneToOne relation with PrimaryKeyJoinColumn?
The problem is that it seems to work only for read, not for write.
Consider the following sample:
@Entity
@Table(name="TRANS", schema="TEST")
public class Transaction {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="CUST_SEQ")
private int urn;
@OneToOne(cascade=CascadeType.ALL) @PrimaryKeyJoinColumn
private TransStatus transStatus;
}
@Entity
@Table(name="TRANSSTATUS", schema="TEST")
public class TransStatus {
@Id
private int urn;
}
Transaction trans = new Transaction();
TransStatus transStatus = new TransStatus();
trans.setStatus(transStatus);
em.getTransaction().begin();
em.persist(trans);
em.getTransaction().commit();
By commit EclipseLink makes two inserts:
INSERT INTO TEST.TRANSSATUS (URN) VALUES (?)
[0]
INSERT INTO TEST.TRANS (URN) VALUES (?)
[234]
I expect that primary key generated for Transaction will be automatically used for TransStatus, but it not the case - it is always set to 0.
If I remove CascadeType.ALL and save objects with two persist calls, it works fine by reading.
Is it design behaviour or I do something wrong?
Unfortunately I cannot use @SecondaryTable with inner join here, because there are some old transactions without status and I should get them by find also.
Reagrds,
Andrei.