Search code examples
spring-bootspring-data-jpaspring-data-envers

No revision data from repository with Spring Data Envers


I've implemented a Spring Data JPA+Envers repository which works fine, according to what I've been monitoring into the database.

@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> {
}

But I can't manage to retrieve revision informations in my test:

@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())));
}}

I can't find if this is strutural or just a testing environment problem. I will take any advice :-)


Solution

  • Well... Apparently just a test issue: @SpringBootTest solved it :-(

    metadata is still null, though