|stale data refreshed after a size()? [message #651548]
||Mon, 31 January 2011 15:43
| Tom Eugelink
Registered: July 2009
I've got one of those things again: modified data is not loaded unless I do a size(). I suspect no one will be able to help me, and the problem is weird and complex, but if not asked, it cannot be answered.|
I have a BM which a.o. contains data for a stock count; you know, where one actually goes into a storage and counts what is there, in order to compare it to what the computer says should be there.
The whole stockcount consist of the following entities:
- one-to-many stockcount-list
- one-to-many stockcount-listitems
- and listitem refers to a storage location.
This is all managed in a Swing application; a stockcount is fetched, the list of stockcount-lists is shown in a JList and the user can select one of those and edit the actual listitems in a JTable. This all works fine.
Now, these stockcounts maybe be kept around for a while, but the storages maybe be rearranged, so the reference of listitem to a storage location can be severed (set to null) in order to prevent FK issues (the storage's description is kept).
This is done at the press of a JButton, after which all the listitems have their reference to storage set to null. This works as well.
The problem is that if, before pressing this sever-button, a stockcount-list had its listitems shown on screen, their storages have not been set to null.
So it seems these were missed, while in fact they were not; the application seems to be using stale data.
After spending the better part of the day hunting down this problem, I'm in the situation where one line below solves the problem. Commenting it out and the problem is there, putting it back in and it is gone.
// Set the to-be-displayed stockcount and refresh the stockcoint-list JList.
iStockcount = value;
if (value != null) value.getStockcountListsWhereIAmStockcount().size(); // <---- this line here
I cannot see how simply calling a size function can have any influence on the rest of my application. NO OTHER CODE IS CHANGED, it is just this line commented or not.
I can move this line a few lines down or up, as long as it is present in that method, it'll work.
The listmodel does this:
class StockcountListListModel extends AbstractListModel
public Object getElementAt(int index)
if (getStockcount() == null) return null;
return getStockcount().getStockcountListsWhereIAmStockcount().get(i ndex);
public int getSize()
if (getStockcount() == null) return 0;
return getStockcount().getStockcountListsWhereIAmStockcount().size( );
Anyone ever experienced a similar situation?
Powered by FUDForum
. Page generated in 0.03578 seconds