Hello,
I have a problem to use unidirectional OneToMany in case if foreign key in second table is not nullable.
Sample:
Entities Transaction and Card are related as OneToMany:
@Entity
@Table(name = "TRANS", schema="TEST")
public class TransactionType {
...
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="TRANS_ID")
public java.util.Set<Card> getCards() {
return cards;
}
}
@Entity
@Table(name = "CARD", schema="TEST")
public class CardUseTypeJAXB {
…
}
The problem is that TRANS_ID column in CARD table is not nullable.
Eclipse Link generates three SQL statements:
1) INSERT INTO TEST.TRANS (URN, NAME) VALUES (?, ?)
bind => [28, 0000001Z]
2) INSERT INTO TEST.CARD (URN, NUMBER) VALUES (?, ?)
bind => [6, 12345]
3) UPDATE TEST.CARD SET TRANS_ID ? WHERE (URN = ?)
The third statements throws exception if TRANS_ID column is not nullable: Column 'TRANS_ID' doesn't
accept Null value. (with nullable column all works fine).
Unfortunately I cannot change the DB schema.
Is there any way to solve this problem?
Regards,
Andrei.