Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify the seed value of version #649

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion api/src/main/java/jakarta/persistence/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,26 @@
* {@code long}, {@link Long}, {@code java.sql.Timestamp},
* {@link java.time.Instant}, {@link java.time.LocalDateTime}.
*
* <p>This field declares a version number:
* <p>Any <strong>positive number</strong> or <strong>non-null timestamp</strong>
* initial value will be the seed of version, otherwise vendors are free to
* seed the version.
Comment on lines +44 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this actually addresses the real actually-known use case here which is to enable a portable way to choose between an initial version of 0 and an initial version of 1.

With this language:

@Version int version = 1;

lets me portably get an initial value of 1. OK, great.

But:

@Version int version = 0;

Just does something non-portable and vendor-specific.

So there's no portable way to request an initial value of 0.

Is that correct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's no portable way to request an initial value of 0.

Yes, there is no way to differ int version = 0; from int version;, both of them should be treated as non-predefined, if negative numbers are treated that way, why not zero?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if negative numbers are treated that way, why not zero?

Well, because counting from 0 is perfectly legit, and often used in computing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it's what Hibernate does by default, so it can't be terrible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if negative numbers are treated that way, why not zero?

Well, because counting from 0 is perfectly legit, and often used in computing.

I'm not against that if EclipseLink team would like to support counting from 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, so it's something that needs to be discussed properly with @lukasj and we need to think through the full impact. i.e. we need an issue to track this. We can't just make this sort of change as a PR with no discussion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need an issue to track this.

Could you reopen #600?

*
* <p>This field declares a version number, the version seed is vendor-specific:
*
* {@snippet :
* @Version
* @Column(name = "REVISION")
* protected int version;
* }
*
* <p>This field declares a version number, the version seed is <code>1</code> across vendors:
*
* {@snippet :
* @Version
* @Column(name = "REVISION")
* protected int version = 1;
* }
*
* <p>This field declares a revision timestamp:
*
* {@snippet :
Expand Down
5 changes: 5 additions & 0 deletions spec/src/main/asciidoc/ch02-entities.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,11 @@ hierarchy, or by one of its mapped superclasses. A portable application
must not declare a version field or property in a subclass of the root
class of an entity class hierarchy.

Any *positive number* or *non-null timestamp* initial value will be the seed of version,
otherwise vendors are free to seed the version. A portable application
should declare a version number field with positive initial value
to make the seed deterministic.

=== Basic Types [[a486]]

The following Java types are considered _basic types_:
Expand Down