• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

About pessimistic locking element collections to prevent it being update by a new transaction

 
Ranch Hand
Posts: 1738
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 1738
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 1738
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 1738
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!