Spring boot 为什么Spring数据环境修订类型返回未知?

Spring boot 为什么Spring数据环境修订类型返回未知?,spring-boot,hibernate,spring-data-jpa,hibernate-envers,spring-data-envers,Spring Boot,Hibernate,Spring Data Jpa,Hibernate Envers,Spring Data Envers,我试图实现的是在响应中输出未知的修订类型,但在数据库中存在revtype。以下是答复: { "metadata": { "delegate": { "id": 1, "timestamp": 1594199577086, "revisionDate": "2020-07-08T09:12:57.086+0000" },

我试图实现的是在响应中输出未知的修订类型,但在数据库中存在revtype。以下是答复:

{
  "metadata": {
    "delegate": {
      "id": 1,
      "timestamp": 1594199577086,
      "revisionDate": "2020-07-08T09:12:57.086+0000"
    },
    "revisionNumber": 1,
    "revisionDate": "2020-07-08T16:12:57.086",
    "revisionInstant": "2020-07-08T09:12:57.086Z",
    "revisionType": "UNKNOWN",
    "requiredRevisionInstant": "2020-07-08T09:12:57.086Z",
    "requiredRevisionNumber": 1
  },
  "entity": {
    "id": 2,
    "roleCode": "ROLE001",
    "roleName": "Admin",
    "isInternal": false,
    "isDeleted": false,
    "createdDate": "2020-07-08T09:12:56.723+0000",
    "modifiedDate": "2020-07-08T09:12:56.723+0000",
    "createdBy": "someone",
    "modifiedBy": null,
    "roleDt": [
      {
        "id": 2,
        "moduleName": "SALES",
        "permission": "ALL"
      },
      {
        "id": 3,
        "moduleName": "Report",
        "permission": "ALL"
      },
      {
        "id": 4,
        "moduleName": "Dashboard",
        "permission": "ALL"
      }
    ]
  },
  "revisionNumber": 1,
  "requiredRevisionInstant": "2020-07-08T09:12:57.086Z",
  "requiredRevisionNumber": 1,
  "revisionInstant": "2020-07-08T09:12:57.086Z"
}
首先,我使用SpringDataEnvers进行开发,将修订类型打印出来插入/更新/删除,当修订类型未知时,我不会重新激活。 这是我的模型: RoleHd.java

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Audited
@EntityListeners(AuditingEntityListener.class)
@EqualsAndHashCode(of = "id")
@ToString(of = {"id"})
@Table(name= "msRoleHd")
public class RoleHd {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long id;

    @NotBlank
    public String roleCode;

    @NotBlank
    public String roleName;

    @NotNull
    public Boolean isInternal;

    public Boolean isDeleted = false;

    @CreatedDate
    private Date createdDate;
    @LastModifiedDate
    private Date modifiedDate;
    @CreatedBy
    private String createdBy;
    @LastModifiedBy
    private String modifiedBy;

    @OneToMany(mappedBy = "roleHd", cascade = CascadeType.ALL)
    public List<RoleDt> roleDt;

    @JsonIgnore
    @OneToMany(mappedBy = "roleHd", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    public List<UserPartnerRole> userPartnerRole;
}
下面是我如何保存数据RoleHdService.java的:

public RoleHd save(InputRequest<RoleHd> request) {
    String currentUser = request.getLoggedInUser();
    RoleHd roleHd = request.getObject();

    if(roleHdRepository.findByroleCodeIgnoreCase(roleHd.getRoleCode()).isPresent()){
        throw new ResourceAlreadyExistException("Role Code "+ roleHd.getRoleCode() +" already exists!");
    }
    
    roleHd.setCreatedBy(currentUser);
    roleHd.getRoleDt().forEach(d -> d.setRoleHd(roleHd));

    return roleHdRepository.save(roleHd);
}

在修订类型打印未知之前,我做错了什么?

找到了答案,这是来自Spring Data Envers的错误,我在本期中发现了:

我猜它在2.2.5以上的版本中得到了解决,我的项目使用的是2.2.5版本的spring data envers,我的spring boot版本是2.2.5,然后我只是将我的spring boot项目版本更新为2.3.1,其他依赖项在后面,修订类型现在打印出来

但我发现它破坏了我整个模型中的javax.validation标记,我将就此开始另一个问题

public RoleHd save(InputRequest<RoleHd> request) {
    String currentUser = request.getLoggedInUser();
    RoleHd roleHd = request.getObject();

    if(roleHdRepository.findByroleCodeIgnoreCase(roleHd.getRoleCode()).isPresent()){
        throw new ResourceAlreadyExistException("Role Code "+ roleHd.getRoleCode() +" already exists!");
    }
    
    roleHd.setCreatedBy(currentUser);
    roleHd.getRoleDt().forEach(d -> d.setRoleHd(roleHd));

    return roleHdRepository.save(roleHd);
}
public Revision<Integer, RoleHd> findByIdLatest(Long id) {

    return roleHdRepository.findLastChangeRevision(id).orElseThrow(() -> new ResourceNotFound("Role "+ id +" not found!"));
}
@SpringBootApplication
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
@EnableJpaAuditing
public class B2bApiApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(B2bApiApplication.class, args);
    }

}