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

@Version type should support primitive #2652

Merged
merged 1 commit into from
Nov 20, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ private Object increment(Object previousValue, Class<?> type) {
}
if (Temporal.class.isAssignableFrom(type)) {
return newTemporal(type);
} else if (type == Integer.class) {
} else if (type == Integer.class || type == int.class) {
return (Integer) previousValue + 1;
} else if (type == Long.class) {
} else if (type == Long.class || type == long.class) {
return (Long) previousValue + 1L;
} else if (type == Short.class) {
} else if (type == Short.class || type == short.class) {
return (Short) previousValue + (short) 1;
} else {
throw new DataAccessException("Unsupported @Version type: " + type);
Expand All @@ -119,11 +119,11 @@ private Object increment(Object previousValue, Class<?> type) {
private Object init(Class<?> valueType) {
if (Temporal.class.isAssignableFrom(valueType)) {
return newTemporal(valueType);
} else if (valueType == Integer.class) {
} else if (valueType == Integer.class || valueType == int.class) {
return 0;
} else if (valueType == Long.class) {
} else if (valueType == Long.class || valueType == long.class) {
return 0L;
} else if (valueType == Short.class) {
} else if (valueType == Short.class || valueType == short.class) {
return (short) 0;
} else {
throw new DataAccessException("Unsupported @Version type: " + valueType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ class VersionGeneratingEntityEventListenerSpec extends Specification {
then:
entity.ver
}

void "test primitive version set"() {
when:
def entity = new ThePrimitiveEntity()
def mockEvent = new DefaultEntityEventContext(PersistentEntity.of(ThePrimitiveEntity), entity)
entityEventListener.prePersist(mockEvent)
then:
entity.ver == 0
when:
entityEventListener.preUpdate(mockEvent)
then:
entity.ver == 1
}
}

@MappedEntity
Expand All @@ -41,3 +54,13 @@ class TheEntity {
@Version
Instant ver
}

@MappedEntity
class ThePrimitiveEntity {
@Id
@AutoPopulated
UUID uuid

@Version
long ver
}
Loading