• 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
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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

 
Ranch Hand
Posts: 1703
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: 1703
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: 1703
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: 1703
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.


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!