Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@Version and Locking.

 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends..

i have a mapping table with Hibernate Annotation..
i added @Version like this..


but the value not changed every updates...

does the value would be changed every update or i have to set the value manually?
does all of the entities has to has field @Version?..

if i created transaction by Locking (LockMode.UPGRADE)..
do i have to use field @Version also..

sorry for the basic question.. iam confused..

Thanks in advance..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you commiting your transaction? The Version will be incremented each successful update.

LockModes are for pessimistic locking, version is for optimistic locking. Which one are you trying to use?
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Paul Sturrock

Thanks sir for your reply..

Yes i have commited my transaction.. but the field @Version value not updated..
is my configuration true?..

Which one is good for implementation Pessimistic Locking or Optimistic Locking?..

Thanks in advance..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Which one is good for implementation Pessimistic Locking or Optimistic Locking?..

Which one do you need? It depends on your requirements. If you are not sure google the two terms before changing your Hibernate code any more.

Are you saying that version sometimes works or never works?
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yap, the version never work.. always have 0 (zero) value every updated..

for web application, which one is common implementation? (Pessimistic Locking or Optimistic Locking)..
Thanks..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You understand what they terms mean, yes? Then think about it, which is preferable for a multiuser system?
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Paul Sturrock

Okay thanks sir..

the field @Version could be updated every updates to My Table..

My conclusion is.. Yap the preferable for multiuser is using Optimistic Locking..

Thanks in advance sir..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Precisely

Is versioning still not working?
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yap sir..

The versioning can working now..
i did a silly mistake, i forgot to add the line of code like this :


Okay thanks in advance sir..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic