Thanks for the patch Dianne, but I have a couple of questions.
1. The javadoc for lock() and refresh() is very similar regarding detached entities :
For lock() :
@throws IllegalArgumentException if the instance is not an
entity or is a detached entity
For refresh() :
@throws IllegalArgumentException if the instance is not
an entity or the entity is not managed
Seems like we'd want to the same thing for refresh and lock (basically the if check for REFRESH can be removed).
2. This is more of a general question - your patch didn't introduce it but the assertValidAttchedEntity() method is very similar to contains(). There is a subtle difference in that contains checks whether the type is managed by this persistence context, and assertValidAttachedEntity checks whether the StateManager is persistent. There's also a slight difference in the exceptions thrown. Still it seems like we'd want to reuse the logic, and rather than duplicating the code.