Question

I'm new to JPA and have noticed that one can make use of optimistic locking by annotating a field in an entity with @Version. I'm just curious about whether persistence providers will create an implicit version field if there doesn't exist one before. For example the website of objectdb states:

"When using ObjectDB, optimistic locking is enabled by default and fully automatic."

But this seems to be vendor-specific behaviour since optimistic locking won't be enabled by default in EclipseLink, for example. So if I want to use locking (and yes, I want :-) ), am I required to create an extra attribute for all my entities? Are there any hints in the specification?

Thank you in advance!

Was it helpful?

Solution

Yes, the JPA @Version annotation allows you to define a version property, I assume ObjectDB just creates a this property by default.

Your own property can be an Integer, Long or Short (or their primitive equivalents), or a java.sql.Timestamp.

Most JPA providers I'm aware of only do optimistic locking if you explicitly use the @Version annotation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top