-1

I found my table has a version column so that hibernate has a error. But what it provides features ? I read the doc , but not understand well.

Javadoc:

/**
 * Additional contract for types which may be used to version (and optimistic lock) data.
 *
 * @author Gavin King
 * @author Steve Ebersole
 */

Thanks.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
fjjiaboming
  • 191
  • 1
  • 3
  • 11

1 Answers1

1

when more than one client wants to update the same data you can choose between:

  • last writer wins
  • when a client loads data which he may edit he locks all others away from using the same data until he releases it (pessimistic)
  • all clients can read/write but get error if attempting to override state which is different from what he has read (optimistic concurrency)

the version column is an implementation of the third strategy. If you get errors chances are you have two clients which try to alter data concurrently.

how to implement optimistic (maybe not the best)

further reading

nice answer when to use what

Community
  • 1
  • 1
Firo
  • 30,626
  • 4
  • 55
  • 94