Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Unidirectional @OneToMany: is it possible with not nullable foreign key?

And how is this "dummy transaction" assigned?
--Gordon

Andrei Shakirin wrote:
Hi Gordon,
 
In such cases cards are assigned with special "dummy" transaction.
Strange design, but it is one legacy DB schema.
 
Regards,
Andrei.


From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Gordon Yorke
Sent: Donnerstag, 16. Juli 2009 16:47
To: EclipseLink User Discussions
Subject: Re: [eclipselink-users] Unidirectional @OneToMany: is it possible with not nullable foreign key?

I am curious.  If Card can be created without being assigned to a Transaction, how is the FK not nullable constraint bypassed in this case?
--Gordon

Andrei Shakirin wrote:
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;
}
----- Original Message -----
Sent: Wednesday, July 15, 2009 1:49 PM
Subject: [eclipselink-users] Unidirectional @OneToMany: is it possible with not nullable foreign key?

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.
 

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users

_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Back to the top