Mutable attributes are death to EOF. That is your problem. Or at least one of them. If you really, really work at it you can probably get it to work, but it is really not worth the effort IMO. Make them immutable. Add cover methods to modify these values: make a mutable clone of the attribute, modify it, make an immutable clone and replace the attribute value. See page 43 of PWO if you have it. If you don't have it, can pretty much assure that you want it!
Are you doing anything else, anywhere, that might be a departure from plain jane EOF? You may be doing something that appears innocent and unrelated which is actually hammering EOF. I am just trying to prod your memory.
It's hard to know. What is an example of something you would consider not plain jane EOF? In InventoryItem, I'm overridding the 'set' methods for a couple of attributes that are likely to change frequently underneath EOF so that it can automatically handle Optimistic locking exceptions. An example of something like that is below. Yesterday after some of our email, I got worried that this may be doing something terrible with regards to EOF, and commented it all out so that everything was using the default implementation (and of course this was also the case when I commented out the entire body of each custom class), but it had no impact whatsoever on the test case that started all of this, so I felt more secure that it was ok to do this kind of thing.
public void setShelfQuantity( Number newValue ) {
Integer existingShelf = (Integer) shelfQuantity();
if ( shelfQuantity() != null && availableQuantity() != null && rawPrimaryKey() != null ) {
int difference = newValue.intValue() - shelfQuantity().intValue();
if ( difference >= 0 ) {
increaseShelfQuantityBy( difference );
increaseAvailableQuantityBy( difference );
} else {
reduceAvailableQuantityBy( difference * -1 );
reduceShelfQuantityBy( difference * -1 );
}
} else {
super.setShelfQuantity( newValue );
setAvailableQuantity( newValue );
}
if ( ( existingShelf == null || existingShelf.intValue() == 0 ) && newValue != null
&& newValue.intValue() > 0 ) {
Enumeration catalogEnum = catalogItems().objectEnumerator();
CatalogItem catalog = null;
while ( catalogEnum.hasMoreElements() ) {
catalog = (CatalogItem) catalogEnum.nextElement();
if ( catalog.futureRelease().intValue() == 1 ) {
catalog.setFutureRelease( new Integer( 0 ) );
}
}
}
}
public void increaseShelfQuantityBy( int numberSold ) {
super.setShelfQuantity( new Integer( shelfQuantity().intValue() + numberSold ) );
// try to save changes but check for conflicts
try {
successfulChangeSave();
} catch ( EOGeneralAdaptorException e ) {
// conflict!! try again on the refaulted object
super.setShelfQuantity( new Integer( shelfQuantity().intValue() + numberSold ) );
try {
successfulChangeSave();
} catch ( EOGeneralAdaptorException f ) {
NSLog.out.appendln( "Multiple conflicts increasing shelf qty!: " + "shelf: "
+ shelfQuantity() + ", avail: " + availableQuantity() + "\n"
+ ErrorStackTrace.toString( f ) );
}
}
}
public void refresh() {
editingContext().invalidateObjectsWithGlobalIDs(new NSArray(editingContext().globalIDForObject(this)));
}
public void successfulChangeSave() throws EOGeneralAdaptorException {
try {
editingContext().saveChanges();
} catch ( EOGeneralAdaptorException f ) {
refresh();
throw f;
}
if ( editingContext().parentObjectStore() instanceof EOEditingContext ) {
try {
( (EOEditingContext) editingContext().parentObjectStore() ).saveChanges();
} catch (EOGeneralAdaptorException f) {
refresh();
throw f;
}
}
}
Chuck
Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.