• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems with locking when loading

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic