Enrico,

    What is the primary key field in the TblScmpdt entity? Did you set primary 
key for tblScmpdt before calling merge? I made an integer primary key field in 
TblScmpdt, and set the primary key to 1 in tblScmpdt before calling merge, and 
your test code works fine for me (I also omit TblPdtbnfcde in your test code 
for lack of detailed information). If you already set the primary key and still 
get the error, please specify more detail of your TblScmpdt class.     
 

-f

--- On Thu, 6/12/08, Enrico Goosen <[EMAIL PROTECTED]> wrote:

> From: Enrico Goosen <[EMAIL PROTECTED]>
> Subject: @OneToMany/@ManyToOne, Bidirectional, Composite Key
> To: [email protected]
> Date: Thursday, June 12, 2008, 7:24 AM
> I can't get cascading persist working on my entities
> which have the following
> mappings.
> 
> TblScmpdt.java //Parent
> @OneToMany(fetch =
> FetchType.LAZY,mappedBy="tblScmpdt",cascade={CascadeType.MERGE,CascadeType.REMOVE})
> private Collection<TblPdtbnf> tblPdtbnfs = new
> ArrayList<TblPdtbnf>();
> 
> TblPdtbnf.java //Child
> @Id
>     @Column(name = "PDTBNF_ID",nullable=false)
>     private Integer pdtbnfId;    //Foreign key to
> TblPdtbnfcde.java
> 
>     @Id
>     @Column(name = "SCMPDT_ID",nullable=false)
>     private Integer scmpdtId; //Foreign key to
> TblScmpdt.java
> 
>  @ManyToOne(fetch =
> FetchType.LAZY,cascade=CascadeType.MERGE)
>     @JoinColumn(name =
> "SCMPDT_ID",referencedColumnName="SCMPDT_ID")
> 
>     private TblScmpdt tblScmpdt;
> 
> --------------------------------------
> 
> Here's the test code:
> 
> em.getTransaction().begin();
>                       
>                       TblScmpdt tblScmpdt = new TblScmpdt();
>                       tblScmpdt.setAdmsysCde("EBSTA");
>                       tblScmpdt.setFndCde("1526");
>                       tblScmpdt.setGccCde("A1526");
>                       tblScmpdt.setPflcmnDte(new Date());
>                       
>                       TblPdtcde tblPdtcde = em.getReference(TblPdtcde.class,
> new Integer(121));
>                       TblPdtbnfcde tblPdtbnfcde =
> em.getReference(TblPdtbnfcde.class, new
> Integer(13));
>                       
>                       tblScmpdt.setPdtcdeId(tblPdtcde.getPdtcdeId());
>                       
>                       TblPdtbnf tblPdtbnf = new TblPdtbnf();
>                       tblPdtbnf.setCmnDte(new Date());
>                       tblPdtbnf.setPdtbnfId(tblPdtbnfcde.getPdtbnfId());
>                       tblPdtbnf.setTblScmpdt(tblScmpdt);
>                       
>                       tblScmpdt.addTblPdtbnf(tblPdtbnf);
> //                    tblScmpdt.getTblPdtbnfs().add(tblPdtbnf);
> 
>                       tblScmpdt = em.merge(tblScmpdt);
>                       
>                       em.getTransaction().commit();
> 
> ----------------------------------
> 
> The exception:
> 
> Caused by: <openjpa-1.0.0-r420667:568756 fatal user
> error>
> org.apache.openjpa.persistence.InvalidStateException:
> Attempt to set column
> "TBL_PDTBNF.SCMPDT_ID" to two different values:
> (null)"null", (class
> java.lang.Integer)"700" This can occur when you
> fail to set both sides of a
> two-sided relation between objects, or when you map
> different fields to the
> same column, but you do not keep the values of these fields
> in synch.
>       at
> org.apache.openjpa.jdbc.sql.PrimaryRow.setObject(PrimaryRow.java:338)
>       at
> org.apache.openjpa.jdbc.sql.RowImpl.flushJoinValues(RowImpl.java:289)
>       at
> org.apache.openjpa.jdbc.sql.RowImpl.flushForeignKey(RowImpl.java:222)
>       at
> org.apache.openjpa.jdbc.sql.RowImpl.setForeignKey(RowImpl.java:197)
>       at
> org.apache.openjpa.jdbc.sql.PrimaryRow.setForeignKey(PrimaryRow.java:172)
>       at
> org.apache.openjpa.jdbc.meta.ValueMappingImpl.setForeignKey(ValueMappingImpl.java:317)
>       at
> org.apache.openjpa.jdbc.meta.FieldMapping.setForeignKey(FieldMapping.java:966)
>       at
> org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.insert(RelationFieldStrategy.java:207)
>       at
> org.apache.openjpa.jdbc.meta.FieldMapping.insert(FieldMapping.java:555)
>       at
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.insert(AbstractUpdateManager.java:203)
>       at
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:145)
>       at
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:85)
>       at
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
>       at
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:514)
>       at
> org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
>       at
> org.apache.openjpa.datacache.DataCacheStoreManager.flush(DataCacheStoreManager.java:544)
>       at
> org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
>       ... 9 more
> 
> -- 
> View this message in context:
> http://www.nabble.com/%40OneToMany-%40ManyToOne%2C-Bidirectional%2C-Composite-Key-tp17801245p17801245.html
> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.


      

Reply via email to