Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with locking when loading

 
Lars Andr�n
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?
 
aswin kumar
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic