| RE: [eclipselink-users] Unidirectional @OneToMany: is it possible with not nullable foreign key? |
|
Hi Andrei,
Thanks for the answer.
It is not really so, card object could exist also without
transaction (for example it can be created just for authentication
purposes) and should be saved into separate DB table.
Unfortunatelly embeddable is not a solution for
me.
Interesting is the following: is it generally possible to
organize unidirectional OneToMany relation if foreign key of "Many" entity is
not nullable?
Is there any solution for it?
Regards,
Andrei. From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Andrei Ilitchev Sent: Mittwoch, 15. Juli 2009 22:06 To: EclipseLink User Discussions Subject: Re: [eclipselink-users] Unidirectional @OneToMany: is it possible with not nullable foreign key? Card object can't exist without the corresponding Transaction
object.
That means Card is not an independent object
(Entity) but rather an owned object (Embeddable),
so OneToMany can't be used (the target must be an
Entity).
I would define Card as Embeddable and use
ElementCollection:
@Entity
@Table(name =
"TRANS",
schema="TEST")
public
class TransactionType {
...
@ElementCollection()
@CollectionTable(name = "CARD", schema="TEST", @JoinColumn(name="TRANS_ID"))
@AttributeOverrides({
@AttributeOverride(name="a", column=@Column(name="URN"), @AttributeOverride(name="b", column=@Column(name="NUMBER"), }) public java.util.Set<Card> getCards() {
return cards;
}
}
@Embeddable
public
class CardUseTypeJAXB {
int a;
int b;
…
}
|