我正在尝试用spring-data-couchbase创建一个数据模型。
我创建了一个名为BaseEntity的超类,其中声明了所有SubClasses的ID和基本字段。@IdSuffix和@IdPrefix批注对我来说工作得很好,但@Field批注不起作用。
我试过@Inheritance,@MappedSuperClass,@Document,...
下面是一个示例:
@Data
@Document
public abstract class BaseEntity {
@IdPrefix(order = 0) // works fine!
@Field //don't work
protected long number;
@IdSuffix(order =0) // works fine!
private UUID uuid;
public BaseEntity(long number){
this.number = number;
this.uuid = UUID.randomUUID();
}
}
@Data
@Document
public class Entity extends BaseEntity{
public Entity(long number){
super(number);
}
@Id
@GeneratedValue(strategy = GenerationStrategy.USE_ATTRIBUTES, delimiter = "::")
private String id;
@Field // works!
private LocalDate date;
}结果是:
id= 1234567::467f970e-ab98-4244-afcf-7af81361d60a
{
"date": 1435301400000
}我希望文档中有字段编号。
发布于 2019-08-22 21:04:08
好了,我解决了这个问题。
@IdPrefix和@Field注解不能一起工作。
解决方案:
@Data
@Document
public abstract class BaseEntity {
@IdPrefix(order = 0) // works fine!
protected long numberPrefix;
@Field // Solution
protected long number;
@IdSuffix(order =0) // works fine!
private UUID uuid;
public BaseEntity(long number){
this.number = number;
this.numberPrefix = number;
this.uuid = UUID.randomUUID();
}
}https://stackoverflow.com/questions/57590510
复制相似问题