带有简单差异的java Javers返回实体\实例\带有抽象实体的\空\ ID
**尝试查找简单差异时发生异常,但如果我将其更改为MappingStyle,则不会引发异常。豆子**
**.withMappingStyle(MappingStyle.BEAN)**
JaversException ENTITY_INSTANCE_WITH_NULL_ID: Found Entity instance 'Employee' with null Id-property 'id' at org.javers.core.metamodel.type.EntityType.getIdOf(EntityType.java:115) at org.javers.core.metamodel.type.EntityType.createIdFromInstance(EntityType.java:122)
@SuperBuilder
@MappedSuperclass
@Data
@EqualsAndHashCode(of= "id")
@EntityListeners(AuditingEntityListener.class)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
public abstract class BaseEntity {
@DiffIgnore
@Id
@Column(name = "id", columnDefinition = "uuid",updatable=false, unique=true, nullable=false)
@GeneratedValue
private UUID id;
@DiffIgnore
@Column(name="\"createDateTime\"", updatable=false, nullable=false)
@CreationTimestamp
private LocalDateTime createDateTime;
@DiffIgnore
@LastModifiedBy
@Column(name="\"createUser\"", updatable=false, nullable=false, length=100)
private String createUser;
@DiffIgnore
@Column(name="\"modifiedDateTime\"", nullable=false)
@UpdateTimestamp
private LocalDateTime modifiedDateTime;
@DiffIgnore
@LastModifiedBy
@Column(name="\"modifiedUser\"", nullable=false, length=100)
private String modifiedUser;
}
@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@TypeName("Employee")
public class Employee extends BaseEntity {
public Employee(String name) {
super();
this.name = name;
}
private String name;
private String position;
private int salary;
private int age;
private Employee boss;
@Builder.Default
private List<Employee> subordinates = new ArrayList<>();
private Address primaryAddress;
private Set<String> skills;
}
@Test
void compareTwoEntitiesTest() {
//given
Javers javers = JaversBuilder.javers()
.withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE)
.build();
UUID id = UUID.randomUUID();
Employee oldEntity = Employee.builder()
.id(id)
.name("Frodo")
.age(40)
.position("Townsman")
.salary(10_000)
.boss(new Employee("Gandalf"))
.primaryAddress(new Address("Shire"))
.skills(Set.of("management"))
.subordinates(List.of(new Employee("Sam")))
.createDateTime(LocalDateTime.now())
.createUser("ch")
.build();
Employee newEntity = Employee.builder()
.id(id)
.name("Frodo")
.age(41)
.position("Hero")
.salary(12_000)
.boss(new Employee("Gandalf"))
.primaryAddress(new Address("Mordor"))
.skills(Set.of("management", "agile coaching"))
.subordinates(List.of(new Employee("Sam"), new Employee("Sméagol")))
.createDateTime(LocalDateTime.now().plusMinutes(1))
.createUser("zy")
.build();
//when
Diff diff = javers.compare(oldEntity, newEntity);
System.out.println(diff.prettyPrint());
//then
assertThat(diff.getChanges()).hasSize(7);
共 (0) 个答案