Hi, I update the element collection example from JPA Pro,
I locked the employee instance and the lock is extended to the element collection phones.
But why the new transaction (running the updateAPhoneToDefault()) can update the home phone number of that employee?
I assume the employee and the phones entities are locked and no other transaction can update it.
Himai Minh
Ranch Hand
Posts: 1714
12
posted 1 year ago
I tried to use two stateful bean with extended persistence context. One bean lock the entity and a second bean tried to update the entity's phone collection.
But to my surprise, the second bean can update the phone even though it is locked by the first bean.
Is there anything wrong with setting the lock scope in the following code?
Himai Minh
Ranch Hand
Posts: 1714
12
posted 1 year ago
I use PessimisticLockScope.EXTENDED instead of "EXTENDED". And I attempted to remove a phone in the collection. But to my surprise, it does remove the phone.
But still, to my surprise, I expect the phones collection is locked and no phone number is removed.
But actually the home phone is removed even though it is locked.
Himai Minh
Ranch Hand
Posts: 1714
12
posted 1 year ago
I made one more try. I start a new transaction when I remove the home phone. I assume the new transaction cannot obtain the pessimistic lock on the element collection, phones and I assume the home phone cannot be removed in this new transaction. But still, to my surprise, the new transaction can remove the phone which is locked.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database