Skip to main content

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

Andrei,
    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")));"

--Gordon

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
@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?
 
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,
Andrei.
 

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

Back to the top