我正在尝试使用spring-data-envers在Java Spring Boot项目中实现实体审计。所有的实体都像它们应该创建的那样被创建了,但是我在执行查询时遇到了困难。
parentRepository.findRevisions(id).stream().map(Parent::getEntity).collect(Collectors.toList());
在这个选择过程中,存储库也应该从子实体获取信息,而我获取的是unable to find <child object> with {id}。
根据我的实验,在Category_Aud表中搜索categoryId,而不是在包含所需数据的实际表中搜索。
代码片段:
@Data
@Entity
@Audited
@NoArgsConstructor
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Enumerated(EnumType.STRING)
private Status status;
@Enumerated(EnumType.STRING)
private Type requestType;
private String fullName;
@ManyToOne
@JoinColumn(name = "child_id")
private Child child;
}@Data
@Entity
@Audited
@NoArgsConstructor
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String description;
}我已经用RevisionRepository扩展了Parent
@Repository
public interface ParentRepository extends RevisionRepository<Parent, Long, Long>, JpaRepository<Parent, Long>并用@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)注释了我的SpringBootApplication入口类
到目前为止,我找不到任何解释,如何让parentRepository得到我需要的东西?
发布于 2020-12-07 18:39:42
这里的潜在问题是来自版本化实体的引用并没有真正正确地定义。应该返回引用的哪个变体?你用来作为基础的版本开头的那个,结尾的那个?就是现在存在的那个?
在某些情况下,每个变体都是有意义的。
因此,您必须自己查询修订,而不能简单地导航到它们。
https://stackoverflow.com/questions/63263523
复制相似问题