Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
JPAContainer - add item causes StaleStateException
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<JartFilter> 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
In another thread, I was asking about the various persistence libraries I should be using. I have since replaced the somewhat random collection of Hibernate libraries I was working with with the EclipseLink libraries, and then upgraded to the latest JPAContainer and the StaleStateException seems to have disappeared - for now, at least. I'm guessing I had inconsistent versions of the various jar files.
nbc