• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is Hibernate optimistic or pessimistic or both?

 
Mike Okri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like Hibernate is optimistic by default because optimistic-lock attribute of the <class> element has a default value of version

It looks like Hibernate is pessimistic by default because the docs say that every Hibernate connection to a database will use the database’s default isolation level. However, I can change this by setting hibernate.connection.isolation = 4

Is Hibernate optimistic or pessimistic or both?
 
Ogeh Ikem
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither is switched on by default. In order to switch on optimistic locking, you have to add a version or timestamp property to every class. Or you can tell Hibernate to perform version checking by inspecting table fields. In order to switch on pessimistic locking, you have to explicitly use one of the LockModes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic