我有以下简单的数据模型:
为TestUser:
@Entity
@Table(name = "TEST_USER")
@Audited
public class TestUser implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Long id;
@Column(name = "NAME", nullable = false)
@NotEmpty
private String name;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "testUser", fetch = FetchType.LAZY)
@JsonIgnore
@OrderBy
private Set<TestUserAddress> addresses = new HashSet<TestUserAddress>();
// ...
}
TestUserAddress:
@Entity
@Table(name = "TEST_USER_ADDRESS")
@Audited
public class TestUserAddress implements Serializable {
private static final long serialVersionUID = -2071806522133475539L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Long id;
@Column(name = "NAME", nullable = false)
@NotEmpty
private String name;
@Column(name = "CITY", nullable = false)
@NotEmpty
private String city;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "TEST_USER_ID")
@JsonBackReference
private TestUser testUser;
// ...
}
我已执行一项操作来更新TestUserAddress对象 - 例如我更改了TestUserAddress名称:
[TestUser]:
- id = 1
- name = "testName"
- [TestUserAddress]:
- name = "testAddressName" ===> changed to "testAddressName2"
- city = "testAddressCity"
我开发了一些代码来比较TestUser对象,如下所示:
// testUserId - ID of the object that I would like to compare
// startRevision/endRevision - revisions to compare - stored in Hibernate Envers audit tables
AuditReader testUserReader = AuditReaderFactory.get(em);
TestUser testUserStart = testUserReader.find(TestUser.class, testUserId, startRevision.intValue());
TestUser testUserEnd = testUserReader.find(TestUser.class, testUserId, endRevision.intValue());
Javers javers = JaversBuilder.javers().build();
Diff diff = javers.compare(testUserStart, testUserEnd);
但是上面的代码没有显示我对TestUserAddress所做的更改。 如果我在代码下面运行:
// testUserId - ID of the object that I would like to compare
// startRevision/endRevision - revisions to compare - stored in Hibernate Envers audit tables
AuditReader testUserReader = AuditReaderFactory.get(em);
TestUser testUserStart = testUserReader.find(TestUser.class, testUserId, startRevision.intValue());
Set<TestUserAddress> testUserAddressStart = testUserStart.getAddresses();
TestUser testUserEnd = testUserReader.find(TestUser.class, testUserId, endRevision.intValue());
Set<TestUserAddress> testUserAddressEnd = testUserEnd.getAddresses();
Javers javers = JaversBuilder.javers().build();
Diff diff = javers.compare(testUserStart, testUserEnd);
Diff diff2 = javers.compare(testUserAddressStart, testUserAddressEnd);
diff2变量显示了对TestUserAddress所做的所有更改,但是我想对根对象执行compare
操作,以获取对象字段和所有子对象的完整列表。
你知道我该怎么办?
我将不胜感激任何帮助。谢谢。