Hi Fay,

I tried out your suggestion:
@ManyToOne(fetch = FetchType.LAZY,cascade=CascadeType.MERGE)
@JoinColumn(name = "XYZ_ID",referencedColumnName="SCMPDT_ID") 
private TblScmpdt tblScmpdt;

But unfortunately, still no luck.
Got this exception:
<openjpa-1.1.0-r422266:657916 fatal store error>
org.apache.openjpa.persistence.RollbackException: DB2 SQL error: SQLCODE:
-407, SQLSTATE: 23502, SQLERRMC: TBSPACEID=2, TABLEID=263, COLNO=0
        at
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:523)
        at test.za.co.metcapri.Tester.test(Tester.java:100)
        at test.za.co.metcapri.Tester.main(Tester.java:21)
Caused by: <openjpa-1.1.0-r422266:657916 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: DB2 SQL error: SQLCODE:
-407, SQLSTATE: 23502, SQLERRMC: TBSPACEID=2, TABLEID=263, COLNO=0
FailedObject: prepstmnt 14779369 INSERT INTO EBSTATUS.TBL_PDTBNF (PDTBNF_ID,
SCMPDT_ID, CMN_DTE) VALUES (?, ?, ?)
[org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement]

SQLSTATE 23502: An insert or update value is null, but the column cannot
contain null values.

The closest I came to solving this problem was a suggestion I saw in the
Hibernate forums, where a user was experiencing the same problem.
http://forum.hibernate.org/viewtopic.php?t=987126&highlight=detached&sid=48c7ceada0b8df5718275a74d6dcafc4
http://forum.hibernate.org/viewtopic.php?t=987126&highlight=detached&sid=48c7ceada0b8df5718275a74d6dcafc4
 

I changed TblPdtbnf.class to use an @EmbeddedId:

@EmbeddedId
private TblPdtbnfPK tblPdtbnfPK;

Changed TblPdtbnfPK to @Embeddable.

I also had to modify the setters on TblPdtbnf like so:

public void setTblScmpdt(TblScmpdt tblScmpdt) {
        this.tblScmpdt = tblScmpdt;
        if(this.tblPdtbnfPK == null){
                this.tblPdtbnfPK = new TblPdtbnfPK();
        }
        if(tblScmpdt != null){
                this.tblPdtbnfPK.setScmpdtId(tblScmpdt.getScmpdtId());
        }
}
public void setTblPdtbnfcde(TblPdtbnfcde tblPdtbnfcde) {
        this.tblPdtbnfcde = tblPdtbnfcde;
        if(this.tblPdtbnfPK == null){
                this.tblPdtbnfPK = new TblPdtbnfPK();
        }
        if(tblPdtbnfcde != null){
                this.tblPdtbnfPK.setPdtbnfId(tblPdtbnfcde.getPdtbnfId());
        }
}

I was able to perform a cascading persist, but when I checked the database,
there were two new columns on TBL_PDTBNF, viz. scmpdtId, and pdtbnfId, in
addition to the existing columns SCMPDT_ID and PDTBNF_ID.
I tried renaming the fields on TblPdtbnfPK.class to match the database
columns, to prevent this problem, but that didn't help.

As a last resort, I tried switching JPA providers to Hibernate, and I found
that the problem exists in Hibernate as well.

I give up...:-((
-- 
View this message in context: 
http://www.nabble.com/%40OneToMany-%40ManyToOne%2C-Bidirectional%2C-Composite-Key-BUG-tp17801245p17880499.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to