I have a table which uses a JPAContainer as a data source. I have an ‘Add Record’ button which creates a new entity and adds it to the container/database. This works one time, but the second time I try to add a record, I get the following error:
org.hibernate.StaleStateException: Batch update returned unexpected row cound from update [0]
; actual row count: 0; expected: 1
Followed by a very long stack traceback…
My code in the Button for adding the record looks like this (I’ve removed all the error checking and validation code to simplify the presentation…):
b_AddFilter.addListener(new Button.ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
JartFilter jf = null;
.... validate inputs...
jf = new JartFilter();
jf.setUser(u);
jf.setFilterName(fName);
jf.setRegex(regex);
try{
jc_JartFilters.addEntity(jf);
}
catch(Exception e){
Logger.error("Failed to add Filter: " + jf.getFilterName());
Logger.error("Exception: " + e);
e.printStackTrace();
}
}
}
tbl_JartFilter.select(null);
}
});
The JPAContainer is defined as: JPAContainer jc_JartFilters
and the table uses jc_JartFilters as its source.
Can someone point out what I’m doing wrong with respect to my database access? I also have an update and a delete button on this page. The update routine takes an existing
record and calls jc_JartFilters.addEntity(jf). This can be called repeatedly and it seems to correctly update the selected record. Delete also seems to work, but a
call to addRecord after a delete fails with the same StaleStateException. The delete is handled by calling jc_JartFilters.removeItem(oid) where oid is the table.getValue() (selected row id).
Side Question - why is there an addEntity() but not a removeEntity() or updateEntity() routine? Am I missing something?
thanks,
nbc