Ever feel like ItemStateException is a ghost in your AEM machine? This exception might be seasoned, but it's still haunting many a legacy codebase. I've just published a blog into possible causes and (more importantly) how to make them disappear. Take a look!
A few remarks: * I do not recommend to always do a session.refresh before you save content, as it can cause significant overhead without any benefit. If you have code which is prone to such situations, I would use a different approach and in case of RepositoryExceptions I would try a retry (and doing a Session refresh before).
* And in the end it does not matter if you use the JCR API or the Sling Resource API, you can get these exceptions on both layers. I prefer the Resource API in general, because it's easier to use in most cases.