Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipselink-dev] @OneToMany with not nullable foreign key and OUTER JOIN to Secondary Table

Hi Gordon,
Thanks for the answer!
I will try proposed solution for item 2.
Regarding item 1: bidirectional workaround is of course an option, but I am quite unhappy with it, because it is necessary to change domain object model with attribute for technical puprose only...
Probably there is a way to do it with unidirectional OneToMany?

From: eclipselink-dev-bounces@xxxxxxxxxxx [mailto:eclipselink-dev-bounces@xxxxxxxxxxx] On Behalf Of Gordon Yorke
Sent: Donnerstag, 16. Juli 2009 15:33
To: Dev mailing list for Eclipse Persistence Services; EclipseLink User Discussions
Subject: Re: [eclipselink-dev] @OneToMany with not nullable foreign key and OUTER JOIN to Secondary Table

    We are looking into the first issue but the easiest workaround for you is to map it as a bidirectional one to many
  With Item 2 you can register a DescriptorCustomizer for this Entity then on the descriptor's QueryManager set a custom join _expression_ using the outer join
   "ExpressionBuilder eb = new ExpressionBuilder();  descriptor.getQueryManager().setMultipleTableJoinExpression(eb.getField("EMP.ID").equalsOuterJoin(eb.getField("SECOND.FK")));"


Andrei Shakirin wrote:
Hi Gordon,
I am sorry to posting this into the dev list, but probably you can shortly help me with two following issues:
1.  @OneToMany with not nullable foreign key
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
@Table(name = "TRANS", schema="TEST")
public class TransactionType {
        @OneToMany(cascade = CascadeType.ALL)
        public java.util.Set<Card> getCards() {
                return cards;
@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:
     bind => [28, 0000001Z]
  bind => [6, 12345]
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?
2. OUTER JOIN to Secondary Table
Use case: There is a main employee table that may or may not have some extra data populated in a related secondary table. If there is data in the secondary table (@SecondaryTable), then I would like my Employee entity to have those fields filled in. If there isn't data for a given employee in the secondary table, then I would like my Employee entity to have nulls in those fields. Right now, if there's no row in the secondary table for a given employee, I get nothing.
I cannot use OneToOne relation for this case, because mapping is defined directly for one business domain object.
Unfortunately I cannot find acceptable solution for it.
Is INNER JOIN for Secondary Table fixed by design?
Reagrds and thanks,

_______________________________________________ eclipselink-dev mailing list eclipselink-dev@xxxxxxxxxxx

Back to the top