Skip to content

all-arguments constructor incompatible with '@Version private long version' [DATACOUCH-626] #937

Closed
@spring-projects-issues

Description

@spring-projects-issues

jpringle opened DATACOUCH-626 and commented

When attempting to use an all-arguments constructor as the persistence constructor in conjunction with a @Version property, if the type of the version property is a native type then object instantiation will fail.

Queries and key-value gets fail to construct entities due to an attempt to pass "null" as the version parameter in the all-arguments constructor.

 The following simple document class will fail to load with the following exception:

org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate SubscriptionToken using constructor public SubscriptionToken(java.lang.String,long,java.lang.String,java.lang.String,java.lang.String,java.lang.String,long) with arguments 19df69a7-db2f-4cc0-94f9-d2a15624b5fc,null,SafetyAll,SafetySuper1,appId unknown,deviceId unknown,1601974697119
@Getter
@ToString
@EqualsAndHashCode
@Document
public class SubscriptionToken {
  private @Id @GeneratedValue(strategy = GenerationStrategy.UNIQUE) String id;
  private @Version long version;
  private @Field String subscriptionType;
  private @Field String userName;
  private @Field String appId;
  private @Field String deviceId;
  private @Field long subscriptionDate;

  public SubscriptionToken(
      String id,
      long version,
      String subscriptionType,
      String userName,
      String appId,
      String deviceId,
      long subscriptionDate) {
    this.id = id;
    this.version = version;
    this.subscriptionType = subscriptionType;
    this.userName = userName;
    this.appId = appId;
    this.deviceId = deviceId;
    this.subscriptionDate = subscriptionDate;
  }

Referenced from: pull request #272

Backported to: 4.0.5 (Neumann SR5)

1 votes, 3 watchers

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions