• 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problems with locking when loading

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi hi,
this is my first post on this forum, have been reading for some months now, and like this place better than other Java forums.

Im using Hibernate, and an entity of mine is called "ShoppingRound", and that entity has a relation to another one called "ShoppingDetails". It looks like this:



At one point I load a , and then try to update the column "shopping_time" in it:



The problem is that when trying to load the I get the following exception:



So, it seems like Hibernate is trying to get a lock on a table related to ShoppingRound, although no data from that table is manipulated.
Is this normal Hibernate-behaviour? If so, any suggestions on how I can go around it?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
you are using h2 database,for this database default locking is table level locking(not row level),acquiring table lock is causing time out exception so append MVCC=TRUE to database url.and check,

hope this solves your problem

regards,
 
Lars Andr�n
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Thank you for the help, just like you say, H2 can not do locks on rows, which caused it to try and obtain a lock on the whole table. I was aware of that already though. In the end it proved to be the fact that there were two different threads that were accessing the same object, and that object had a OneToOne-mapping on the second object, so when loading the first object, the second had to follow whether it was used or not.
The first thread accessed the ShopRound and ShopDetails without committing the transaction, thus never letting the ShopDetails go, thus any other attempts to lock it failed.

I solved it by making sure to start and commit a transaction when the first thread accessed the ShopRound.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic