Hi,
I have a very simple postgreSQL database table that contains a few colomns that are of type REAL.
I can easily insert new rows into the table. However, when editing existing rows, each row can be edited 1 time successfully. After that, any updates on that row will generate an UPDATE_ROW_CONFLICT row 0 attempt to update a row that has been updated or deleted by another user.
1. There are no other users in my database (its local on the machine).
2. The problem only happens on the columns of type REAL, I can update columns of type TEXT all day long.
3. This code is modeled after the insert/delete/update example.
4. Shutting down EVERYTHING, moving to Moscow, and restarting everything has the same effect (i.e. rebooting solves nothing!).
I am starting to think the cacheddataprovider is not robust enough for a commercial environment. Doesnt say much for the product. I am not impressed with NetBeans 6.0 at all. Some people have said put a refresh after the commitchanges call, I tried that, didn't solve anything.
Here's the code I use for the OnSave:
public String okbutton_action() {
String ReturnVal = null;
//if (New item). Insert a new row into the database (this always works fine!!)
if (IsNewItem())
{
try {
//Get values from the form;
//Dates are tricky, they have to be converted to SQL dates, can not use java dates;
java.sql.Date SeletedDate = new java.sql.Date(calendar1.getSelectedDate().getTime());
Object Weight = weight.getValue();
Object LongWgt = LCG_Val.getValue();
Object LatWgt = latcg_Val.getValue();
Object VerWgt = vertcg_Val.getValue();
Object WgtComment = comments_val.getValue();
//Set the parameters in the query to set the row cursor to the target row;
aircraft_weighingRowSet.setObject(1, getSessionBean1().getSelectedAircraft());
aircraft_weighingRowSet.setObject(2, SeletedDate);
aircraft_weighingDataProvider.refresh();
//Insert a row into the db table;
RowKey rk = aircraft_weighingDataProvider.appendRow();
//Set db cursor to the new row
aircraft_weighingDataProvider.setCursorRow(rk);
//Set the fields of this row in the database;
aircraft_weighingDataProvider.setValue("aircraft", getSessionBean1().getSelectedAircraft());
aircraft_weighingDataProvider.setValue("weighing_date", SeletedDate);
aircraft_weighingDataProvider.setValue("weight", Weight);
aircraft_weighingDataProvider.setValue("lgcg", LongWgt);
aircraft_weighingDataProvider.setValue("latcg", LatWgt);
aircraft_weighingDataProvider.setValue("vertcg",VerWgt);
aircraft_weighingDataProvider.setValue("comment", WgtComment);
aircraft_weighingDataProvider.commitChanges();
aircraft_weighingDataProvider.close();
ReturnVal = "Ok";
} //try
catch (Exception ex)
{
getSessionBean1().LogFACTSError("Error creating new row!", ex);
} //catch
} //is new item
else
{
try
//HERE IS THE ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Update an existing row in the database (this will only update 1x, then throw an error every time, even if the DB server is rebooted!!!!!
{
//Previous values;
Object OldWeighDate = getSessionBean1().GetWeightsandBalances().GetBasicWeighDate();
//Get values from the form;
java.sql.Date NewDate = new java.sql.Date(calendar1.getSelectedDate().getTime());
Object NewWeight = weight.getValue();
Object NewLongWgt = LCG_Val.getValue();
Object NewLatWgt = latcg_Val.getValue();
Object NewVerWgt = vertcg_Val.getValue();
Object NewWgtComment = comments_val.getValue();
//Set the parameters in the query to set the row cursor to the target row;
aircraft_weighingRowSet.setObject(1, getSessionBean1().getSelectedAircraft());
aircraft_weighingRowSet.setObject(2, OldWeighDate);
aircraft_weighingDataProvider.refresh();
RowKey rk = aircraft_weighingDataProvider.getCursorRow();
if (rk != null)
{
//Set the fields of this row in the database;
aircraft_weighingDataProvider.setValue("aircraft", rk, getSessionBean1().getSelectedAircraft());
aircraft_weighingDataProvider.setValue("weighing_date", rk, NewDate);
aircraft_weighingDataProvider.setValue("weight", rk, NewWeight);
aircraft_weighingDataProvider.setValue("lgcg", rk, NewLongWgt);
aircraft_weighingDataProvider.setValue("latcg", rk, NewLatWgt);
aircraft_weighingDataProvider.setValue("vertcg", rk, NewVerWgt);
aircraft_weighingDataProvider.setValue("comment", rk, NewWgtComment);
aircraft_weighingDataProvider.commitChanges(); //this commit changes fails after 1 update is successful
aircraft_weighingDataProvider.refresh();
ReturnVal = "Ok";
}
}
catch (Exception ex)
{
getSessionBean1().LogFACTSError("Unable to edit row!!! ", ex);
} //catch
}
return ReturnVal;
}