Spring Data Envers 的存储库中没有修订数据
No revision data from repository with Spring Data Envers
我已经实施了一个 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())));
}}
我无法确定这是结构问题还是测试环境问题。我会采纳任何建议:-)
嗯...显然只是一个测试问题:@SpringBootTest 解决了它:-(
元数据仍然为空,但
我已经实施了一个 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())));
}}
我无法确定这是结构问题还是测试环境问题。我会采纳任何建议:-)
嗯...显然只是一个测试问题:@SpringBootTest 解决了它:-(
元数据仍然为空,但