Domanda

The Vaadin book says I can set a column for optimistic locking as follows:

tq.setVersionColumn("OPTLOCK");

However it also says that:

TableQuery assumes that the database will take care of updating the version column by either using an actual VERSION column (if supported by the database in question) or by a trigger or a similar mechanism

How do I take care of updating the version column in the database?

Any help is much appreciated

È stato utile?

Soluzione

If you are using JPA or its implementation you should be able to annotate your beans with:

@Version
private Long version;

So every time you persist you bean the version number will be increased by one automatically. In case you bean has lower/different version number during persisting it means it was changed in meantime and JPA throws Optimistic locking exception.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top