| For clarity, I will split up my responses to your questions into two comments. Regarding question #1:
1) Why would you need to refresh an entity that is locked?
You typically wouldn't need to; however, assume I have two spots in the code which are appropriately decoupled, but ultimately both need to retrieve the same entity by ID from the session. The second spot is not aware the entity is already locked (but it might already be read in!). Therefore a lock + refresh is required to ensure it is locked and no longer stale. Your point, however, is precisely correct - I don't want to refresh the entity if it is already locked! However, the code which is performing the refresh might not be the original code that locked the entity in the first place (think two different business logic units executing within the same simple transaction). That's why it is desired that I am able to check if an entity is locked or not prior to performing the refresh. I would like to stick that sort of logic within my abstract DAO classes, but I am currently not able to perform this check since a refresh at some point might have cleared out the lock status within Hibernate itself. |