问题是,在子类上调用.save()时,我无法将基类成员保存到DB。
我有两个类,分别是A类,B类,在这两个类creationTimestamp,lastUpdatedTimestamp,版本中,我都有三个共同的成员,因为它们很常见,所以我想将它们移到基类中,比如C类。在类A的对象上执行mapper.save(),我没有在数据库中获得类C的成员。
@Getter
@Setter
@DynamoDBDocument
@EqualsAndHashCode
@NoArgsConstructor
abstract class C {
@DynamoDBVersionAttribute
private Long version;
@DynamoDBAutoGeneratedTimestamp(strategy = DynamoDBAutoGenerateStrategy.CREATE)
@DynamoDBTypeConvertedTimestamp
private Long creationTimestamp;
@DynamoDBAutoGeneratedTimestamp(strategy = DynamoDBAutoGenerateStrategy.ALWAYS)
@DynamoDBTypeConvertedTimestamp
private Long lastUpdatedTimestamp;
}
A级:
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@DynamoDBTable(tableName = "A")
public class A {
private String id;
}
现在,如果我对类A的对象执行mapper.save(),它将仅将id保存到db。
A a = A.builder().id("random").build();
mapper.save(a);
它应该显示版本,creationTimestamp,lastUpdatedTimestamp,id,我在这里做错什么了吗?
答案 0 :(得分:0)
您的课程A
需要扩展课程C
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@DynamoDBTable(tableName = "A")
public class A extends C {
private String id;
}