I have been trying to update a DataGrid with data that has just been
uploaded to the server using the LCDS updateItem().
My object relationship is
class project {
Array[Assignment]
}
class Assignment {
Array[Allocation]
}
class Allocation {
int x;
int y;
}
If I have an assignment with 2 allocations, and I upload an assignment
with 2 different allocations, sometimes the data in the DataGrid is
updated correctly, sometimes there are duplicate assignments created,
one with the new data, one with the old. And sometimes nothing happens
at all.
First off, what is the correct order of execution to run an updateItem?
Right now, I run a DataService.updateItem() on all the Allocations, and
then I run a DataService.updateItem() on the parent Assignment. Is
there a bug in the 2.5.1 updateItem() ? Thank you in advance.
protected void finializeImport(List inserts, List updates) {
DataServiceTransaction trans =
DataServiceTransaction.getCurrentDataServiceTransaction();
try {
for ( Object object : updates ) {
Assignment assignment = (Assignment)object;
for (Allocation alloc : assignment.getAllocations())
trans.updateItem("allocation.hibernate", alloc,
null, null);
trans.updateItem("assignment.hibernate", assignment,
null, null);
}
if ( 0 < inserts.size() ) {
assignProject = (Assignment)inserts.get(0);
project = assignProject.getProject();
}
else if ( 0 < updates.size() ) {
assignProject = (Assignment)updates.get(0);
project = assignProject.getProject();
}
if ( null != project ) trans.updateItem("project.hibernate",
project, null, new String[] {"assignments"});
if ( true == selfManaged ) trans.commit();
}
catch (Exception e) {
if ( true == selfManaged ) trans.rollback();
}
}