根据我对数据库的监控,我已经实现了一个运行良好的 Spring Data JPA+Envers 存储库。
@SpringBootApplication
@EnableTransactionManagement
@EnableEnversRepositories
public class ToDoApplication {
public static void main(String[] args) {
SpringApplication.run(ToDoCloneApplication.class, args);
}
}
@Entity @Table(name = "Todos")
@Audited(withModifiedFlag = true)
public class Todo {
@Id @GeneratedValue
private Long id;
...
@Transient
private RevisionMetadata<Integer> metadata; // not sure of what it's worth, always null anyway
}
public interface TodosRepository extends JpaRepository<Todo, Long>, RevisionRepository<Todo, Long, Integer> {
}
但我无法在我的测试中检索修订信息:
@DataJpaTest
@Slf4j
class TodoDomainTests {
@Autowired
private TodosRepository dao;
@Test
void tasksPersistence() {
log.info("SETUP...");
Todo todo = new Todo(...);
log.info("PERSISTENCE...");
todo = dao.save(todo);
log.info("UPDATE...");
todo.setContent("Oups! Program shift, everybody...");
todo = dao.saveAndFlush(todo);
// todo = dao.getById(todo.getId());
assertFalse(dao.findRevisions(todo.getId()).isEmpty()); // TEST FAILURE
dao.findAll().stream().mapToLong(Todo::getId)
.forEach(id -> dao.findRevisions(id)
.forEach(rv -> log.info("AVAILABLE REVISION: {} for {}", rv.getMetadata(), rv.getEntity())));
}}
我找不到这是结构问题还是只是测试环境问题。我会接受任何建议:-)