我有一个像这样的超级实体类:
@Getter
@Setter
@NoArgsConstructor
public class GenericEntity {
@Id
private Long id;
@JsonIgnore
@CreatedBy
private Long createdBy;
@JsonIgnore
@CreatedDate
private Long createdDate;
@JsonIgnore
@LastModifiedBy
private Long updatedBy;
@JsonIgnore
@LastModifiedDate
private Long updatedDate;
@JsonIgnore
@Version
private Integer version = 0;
}
并且 Role 类从 GenericEntity 扩展,如下所示:
@Getter
@Setter
@NoArgsConstructor
public class Role extends GenericEntity {
private String name;
private String desc;
private Integer sort;
}
之后我有这样的界面 RoleRepo :
@Repository
public interface RoleRepo extends ReactiveCrudRepository<Role, Long>;
在路由器功能中,我有 2 个处理程序方法
private Mono<ServerResponse> findAllHandler(ServerRequest request) {
return ok()
.contentType(MediaType.APPLICATION_JSON)
.body(roleRepo.findAll(), Role.class);
}
private Mono<ServerResponse> saveOrUpdateHandler(ServerRequest request) {
return ok()
.contentType(MediaType.APPLICATION_JSON_UTF8)
.body(request.bodyToMono(Role.class).flatMap(role -> {
return roleRepo.save(role);
}), Role.class);
}
findAllHandler 方法工作正常,但 saveOrUpdateHandler 抛出如下异常:
java.lang.IllegalStateException: Required identifier property not found for class org.sky.entity.system.Role!
at org.springframework.data.mapping.PersistentEntity.getRequiredIdProperty(PersistentEntity.java:105) ~[spring-data-commons-2.2.0.M2.jar:2.2.0.M2]
at org.springframework.data.r2dbc.function.convert.MappingR2dbcConverter.lambda$populateIdIfNecessary$0(MappingR2dbcConverter.java:85) ~[spring-data-r2dbc-1.0.0.M1.jar:1.0.0.M1]
但是当我搬家时
@Id
private Long id;
从 GenericEntity 类到 Role 类,这两种方法都可以正常工作。Spring Reactive Data 中是否有类似的注释 @MappedSuperclass/JPA
我希望所有扩展类的 GenericEntity 中的 id 字段
谢谢你的帮助
对不起,我的英语太差了