Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Specifying a sequence as the pk generator for a many-to-many-join table relationship

We have a many-to-many relationship between Receipt and CashBatch.

We have a cash_batch_receipt join table with:
  - id NUMERIC (primary key)
  - cash_batch_id NUMERIC (foreign key to cash_batch)
  - receipt_id NUMERIC (foreign key to cash_batch)

and a SeqCashBatchReceiptJoin for generating pk values.

How can we map this so that the sequence is used to generate the ID pk value?

The following did not work.


[In JpaCashBatch...]

   @ManyToMany(targetEntity=JpaReceipt.class,
mappedBy="cashBatchList", fetch=FetchType.LAZY)
    @GeneratedValue(strategy=GenerationType.SEQUENCE,
generator="SeqCashBatchReceiptJoin")
    @JoinTable (
        name="cash_batch_receipt_join",
        joinColumns=@JoinColumn(name="cash_batch_id",
referencedColumnName="id"),
        inverseJoinColumns=@JoinColumn(name="receipt_id",
referencedColumnName="id")
    )


[In JpaReceipt...]

    @ManyToMany(targetEntity=JpaCashBatch.class, fetch=FetchType.LAZY)
    @GeneratedValue(strategy=GenerationType.SEQUENCE,
generator="SeqCashBatchReceiptJoin")
    @JoinTable (
        name="cash_batch_receipt_join",
        joinColumns=@JoinColumn(name="receipt_id", referencedColumnName="id"),
        inverseJoinColumns=@JoinColumn(name="cash_batch_id",
referencedColumnName="id")
    )
    private List<CashBatchEntity> cashBatchList = null;


We get:

java.sql.SQLException: ORA-01400: cannot insert NULL into
("CIS"."CASH_BATCH_RECEIPT_JOIN"."ID")

Error Code: 1400 Call: INSERT INTO cash_batch_receipt_join
(cash_batch_id, receipt_id) VALUES (?, ?) bind => [1002, 1191] Query:
DataModifyQuery(sql="INSERT INTO cash_batch_receipt_join
(cash_batch_id, receipt_id) VALUES (?, ?)")

Thanks!   I couldn't find any information on many-to-many JPA mappings
for tables with independent primary keys.

Regards,
Mike


Back to the top