You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Enrico Goosen <eg...@metropolitan.co.za> on 2008/06/13 11:27:52 UTC

Re: @OneToMany/@ManyToOne, Bidirectional, Composite Key BUG

This is clearly a bug in OpenJPA, because the IdClass' field is not getting
sychronized with the Entities Id field.
In this case, TblPdtbnf.scmpdtId is not getting copied to
TblPdtbnfPK.scmpdtId.
Hence this error:
Attempt to set column "TBL_PDTBNF.SCMPDT_ID" to two different values:
(null)"null", (class java.lang.Integer)"700"
-- 
View this message in context: http://www.nabble.com/%40OneToMany-%40ManyToOne%2C-Bidirectional%2C-Composite-Key-BUG-tp17801245p17819665.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: @OneToMany/@ManyToOne, Bidirectional, Composite Key BUG

Posted by Enrico Goosen <eg...@metropolitan.co.za>.
I updated to OpenJPA 1.1.0, and I'm not getting the above exception anymore,
but its still not working 100%.

Updated example code:

em.getTransaction().begin();
			
			TblScmpdt tblScmpdt = new TblScmpdt();
			tblScmpdt.setAdmsysCde("EBSTA");
			tblScmpdt.setFndCde("0001526");
			tblScmpdt.setGccCde("A1526");
			tblScmpdt.setPflcmnDte(new Date());

			TblPdtbnfcde tblPdtbnfcde = em.getReference(TblPdtbnfcde.class, new
Integer(13));
			
			tblScmpdt.setPdtcdeId(tblPdtbnfcde.getTblPdtcde().getPdtcdeId());
			tblScmpdt.setTblPdtcde(tblPdtbnfcde.getTblPdtcde());
			
			//First need to save parent, this wouldn't be necessary if the child
didn't have a composite key
			tblScmpdt = em.merge(tblScmpdt);
			em.flush(); //Have to flush otherwise JPA tries to persist child before
parent
			
			TblPdtbnf tblPdtbnf = new TblPdtbnf();
			tblPdtbnf.setCmnDte(new Date());
			tblPdtbnf.setTblPdtbnfcde(tblPdtbnfcde);
			tblPdtbnf.setPdtbnfId(tblPdtbnfcde.getPdtbnfId());
			tblPdtbnf.setTblScmpdt(tblScmpdt);
			tblPdtbnf.setScmpdtId(tblScmpdt.getScmpdtId()); //this should get done
automatically by JPA
			
			tblScmpdt.getTblPdtbnfs().add(tblPdtbnf);

			//merge again to save child(ren)
			tblScmpdt = em.merge(tblScmpdt);
			
			em.getTransaction().commit();

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