Hi, I am working with OJB on a purchase order 1 to n object on mysql database.


When update the old PO with the new PO (same ID) with some lineitems deleted, it does not delete the Items in the database.


It works correctly when the new PO with addition lineitems, it adds them to the db. but not vice versa.



following is my repository_user.xml and my update code.


<class-descriptor
class="src.SIP.PO"
table="SHEET"
>
<field-descriptor
name="oid"
column="ID"
jdbc-type="VARCHAR"
primarykey="true"
/>
<field-descriptor
name="status"
column="STATUS"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="CreationDateTime"
column="CreatedDate"
jdbc-type="VARCHAR"
/>
<collection-descriptor
name="Items"
collection-class="org.apache.ojb.broker.util.collections.RemovalAwareCollection"
element-class-ref="src.SIP.POItem"
auto-delete="true"
auto-retrieve="true"
auto-update="true"
>
<inverse-foreignkey field-ref="Invoice_id"/>
</collection-descriptor>
</class-descriptor>


  <class-descriptor
     class="src.SIP.POItem"
     table="SHEETDETAIL"
  >
     <field-descriptor
        name="Invoice_id"
        column="SheetID"
        jdbc-type="VARCHAR"
        primarykey="true"
     />
     <field-descriptor
        name="Item_id"
        column="BookID"
        jdbc-type="VARCHAR"
        primarykey="true"
     />
     <field-descriptor
        name="Price"
        column="Price"
        jdbc-type="FLOAT"
     />
     <field-descriptor
        name="Sum"
        column="Sum"
        jdbc-type="FLOAT"
     />
     <field-descriptor
        name="Quantity"
        column="Quantity"
        jdbc-type="INTEGER"
     />

</class-descriptor>

static public void UpdatePO1(String id, PO newpo) {

Implementation odmg = OJB.getInstance();
Database db = odmg.newDatabase();

try {
db.open("default", Database.OPEN_READ_WRITE);
} catch (ODMGException ex) {
ex.printStackTrace();
}

String oqlQuery = "select upd from " + PO.class.getName() + " where oid = " + id;
TransactionImpl tx = (TransactionImpl) odmg.newTransaction();
try{


tx.begin();

PersistenceBroker pb = tx.getBroker();

PO oldpo = getPO(id);

tx.lock(oldpo, Transaction.WRITE);

BeanUtils.copyProperties(oldpo, newpo);

tx.commit();
} catch (Throwable t) {

t.printStackTrace();
}
}

_________________________________________________________________
Instant message in style with MSN Messenger 6.0. Download it now FREE! http://msnmessenger-download.com



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to