What i trying to achieve is the revision type that print out UNKNOWN in the response, but in the database exist the revtype. Here is the response :
{
"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"
}
at first i develop with Spring Data Envers, i have the revision type printed out INSERT/UPDATE/DELETE, i don't relize when the revision type become UNKNOWN. Here is my model : 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;
}
and here is how i save the data 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);
}
here is how i get my revision data from envers :
public Revision<Integer, RoleHd> findByIdLatest(Long id) {
return roleHdRepository.findLastChangeRevision(id).orElseThrow(() -> new ResourceNotFound("Role "+ id +" not found!"));
}
here is my application.java
@SpringBootApplication
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
@EnableJpaAuditing
public class B2bApiApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(B2bApiApplication.class, args);
}
}
what did i do wrong until the revisionType printed unknown?
Found the answer, that's a bug from Spring Data Envers, which is i found in this issue : https://github.com/spring-projects/spring-data-envers/issues/215
and it solved in version above 2.2.5 i guess, my project was using 2.2.5 version of spring data envers and my spring boot version was 2.2.5 and then i just update my spring boot project version to 2.3.1 and the others dependency was following and the revisionType is printed now
but i found it broke my javax.validation tags in my entire model, i will start another question for this