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

Hibernate - PreUpdateEventListener - Locks Table

 
Ally Cavs
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

This code works perfect for one appliction where JTA is used.
The second applictian I am attempting to get this code working in, freezes on the last line. The underlying DB in both cases is SQL Server 2008
What happens is that Hibernates locks the table on the database. I have to release the lock in the DB.



This code takes the item in the DB and compare withs the pue.getEntity(). pue.getEntity() holds the changed entity about to be persisted
This is for auditing purposes.

Now the issue is Hibernate persists the item first with the primary key and with blank fields
Then does an update to fill in the blank fields. So this is all happening in the 1 transaction
(I dont know why - this is hibernate behaviour and hence why im falling into onPreUpdate after onPreInstert)



The second app has the following code to manage transaction handling instead of using JTA. (Glass fish V2 is the server)


onPreUpdate is entered on trx.commit()
Please help. Does my database pool on glassfish need a particular set up
Should I use LockMode when doing retrieve
retrieveSession.get(pue.getEntity().getClass(),Long.valueOf(entityStringID),LockMode.NONE);

I have tried various changes but cant nail it

Alan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic