How to free a locked row using JPA?

I am using the EclipseLink JPA 2.0 implementation, which allows pessimistic locking. I know how to lock an object, but how can I release the lock? At first I thought that all this would be taken care of within the framework of the transaction (in other words, the entity is locked until you complete the transaction), but this does not seem to be the case.

I tried a quick google search (it seems like this should be pretty obvious), but I didn't find anything ...

+5
source share
1 answer

After I get some sleep ... and spend a little more in the morning, I think I figured out my problem. Thus, the lock is actually performed as part of the transaction. However, when I tested my code, I managed to get a locked string using the EntityManager.find method (class, key) (no locking strategy was specified). I mistakenly thought that by putting a lock on a string, the string could not be read. Period. However, I reread the definitions of JPA PESSIMISTIC_READ and PESSIMISTIC_WRITE and noticed my problem:

PESSIMISTIC_READ - , , PESSIMISTIC_WRITE.PESSIMISTIC_WRITE. , , PESSIMISTIC_READ PESSIMISTIC_WRITE.

, READ WRITE .

+9

All Articles