我试图实现的是在响应中打印出UNKNOWN的修订类型,但在数据库中存在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"
}
起初,我使用Spring Data Envers进行开发,我打印出了INSERT/UPDATE/DELETE的修订类型,当修订类型变为UNKNOWN时,我不会重新初始化。这是我的模型: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;
}
RoleDt.java:
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Audited
@EntityListeners(AuditingEntityListener.class)
@Table(name= "msRoleDt")
public class RoleDt {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
public String moduleName;
public String permission;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "roleId")
public RoleHd roleHd;
}
下面是我如何保存数据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);
}
以下是我如何从envers:获得修订数据
public Revision<Integer, RoleHd> findByIdLatest(Long id) {
return roleHdRepository.findLastChangeRevision(id).orElseThrow(() -> new ResourceNotFound("Role "+ id +" not found!"));
}
这是我的应用程序.java
@SpringBootApplication
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
@EnableJpaAuditing
public class B2bApiApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(B2bApiApplication.class, args);
}
}
我做错了什么,直到修订版打印出未知类型?
找到了答案,这是我在本期中发现的Spring Data Envers的一个错误:https://github.com/spring-projects/spring-data-envers/issues/215
它在2.2.5以上的版本中解决了,我想,我的项目使用的是2.2.5版本的spring数据环境,我的spring引导版本是2.2.5,然后我只是将我的spring启动项目版本更新到2.3.1,其他依赖项如下,修订类型现在打印
但我发现它破坏了我整个模型中的javax.validation标签,我将开始对这个提出另一个问题