Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

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


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!