spring 数据 mongo 没有 属性 b 在通过 Id 检索实体时在实体 class 上找到
spring data mongo No property b found on entity class when retrieving entity by Id
我有一个父 class 有一些共享字段和一个扩展它的子 class。
@SuperBuilder(toBuilder = true)
@Data
public abstract class MultiTenantAuthoredDocument {
@Indexed
private String tenantId;
@CreatedDate
private LocalDateTime createdDate;
@LastModifiedDate
private LocalDateTime lastModifiedDate;
}
@Document(collection = "users")
@SuperBuilder(toBuilder = true)
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class User extends MultiTenantAuthoredDocument {
@Id
private String id;
private String firstName;
private String lastName;
@Indexed
private String password;
@Indexed(unique = true)
private String userName;
@Indexed(unique = true)
private String email;
@Indexed
private List<UserRole> roles;
@Builder.Default
private boolean enabled = false;
}
然而,当 运行 我的单元测试时,当我执行 findById 时出现意外异常,结果如下:
No property b found on entity class be.moesmedia.erp.users.domain.User to bind constructor parameter to!
因为我不知道 属性 b 是从哪里来的,所以很难看出我做错了什么。
如果有人能帮我指出我做错了什么。
所以我知道出了什么问题,Lombok 生成了一个构造函数,该构造函数接受具有 SuperBuilder class 属性的对象。一旦我将 @NoArgsConstructor
添加到子项和父项 class,它就像一个魅力。
我有一个父 class 有一些共享字段和一个扩展它的子 class。
@SuperBuilder(toBuilder = true)
@Data
public abstract class MultiTenantAuthoredDocument {
@Indexed
private String tenantId;
@CreatedDate
private LocalDateTime createdDate;
@LastModifiedDate
private LocalDateTime lastModifiedDate;
}
@Document(collection = "users")
@SuperBuilder(toBuilder = true)
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class User extends MultiTenantAuthoredDocument {
@Id
private String id;
private String firstName;
private String lastName;
@Indexed
private String password;
@Indexed(unique = true)
private String userName;
@Indexed(unique = true)
private String email;
@Indexed
private List<UserRole> roles;
@Builder.Default
private boolean enabled = false;
}
然而,当 运行 我的单元测试时,当我执行 findById 时出现意外异常,结果如下:
No property b found on entity class be.moesmedia.erp.users.domain.User to bind constructor parameter to!
因为我不知道 属性 b 是从哪里来的,所以很难看出我做错了什么。
如果有人能帮我指出我做错了什么。
所以我知道出了什么问题,Lombok 生成了一个构造函数,该构造函数接受具有 SuperBuilder class 属性的对象。一旦我将 @NoArgsConstructor
添加到子项和父项 class,它就像一个魅力。