When using Spring Data Envers with Spring Boot, the EnversRevisionRepositoryFactoryBean
has to be configured via @EnableJpaRepositories
:
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
Maybe an auto configuration could take care of it. Would it make sense?
In case it does, I would be happy to prepare a pull request.
Comment From: philwebb
@mp911de Hi Mark, what are your thoughts on this? Is it a sensible thing to auto-configure?
Comment From: mp911de
Adding also @schauder to the conversation.
Envers repositories assume that the entity is audited and allows revision retrieval. From what I’ve seen we cannot expect that this assumption holds true for each application. Instead, only some entities are audited.
Since I’m not exactly sure on the impact on non-audited entities, I’d like Jens to chime in.
Comment From: scordio
Each repository would still need to extend from org.springframework.data.repository.history.RevisionRepository
in order to get revision retrieval methods, so the application still has to properly declare a repository for each audited entity.
If I am not mistaken, a repository extending RevisionRepository
cannot work with Envers if the above configuration is not applied. At the same time, the configuration above should have no impact on repositories not extending from RevisionRepository
.
My idea is that when EnversRevisionRepositoryFactoryBean
(or any other class coming from spring-data-envers
) is in the classpath , most likely the application wants to use Spring Data JPA together with Envers, hence my proposal about the auto configuration.
Comment From: schauder
Pro auto configuration:
- The impact on non audited entities should be minimal. Especially it is well separated from the JPA infrastructure. This impression is supported by the fact that I can't remember a single issue where Spring Data Envers triggered a bug in Spring Data JPA.
Contra:
- Spring Data Envers is rather low usage (~1.5% downloads compared to Spring Data JPA)
- I expect it to be common, that only some entities are audited. As mentioned above this SHOULD not be an issue.
I'm not sure what the criteria are for inclusion of auto configuration, but my gut reaction is: "Yeah, why not"
Comment From: wilkinsona
Thanks, @schauder and @mp911de.
@scordio It sounds like it makes sense to offer some auto-configuration for this. Are you still interested in contributing a pull request? If so, I think it could be implemented by making some changes to org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesRegistrar
.
Comment From: scordio
@wilkinsona yes I am, thanks for the feedback.
I started already hacking around and I was thinking to conditionally register another registrar (extended from JpaRepositoriesRegistrar
) when Envers is around.
I will open a draft PR for some brainstorming and make sure I am going in the right direction.
Comment From: wilkinsona
Excellent. Thank you. Please let us know if you have any questions.
Comment From: wilkinsona
How's it going, @scordio? Please do let us know if you need anything from us.
Comment From: scordio
Hi @wilkinsona, thanks for checking! Unfortunately, in the last weeks I had very limited time to spend on this but I did small advancements.
During the weekend I will put what I have in a good shape and submit the draft PR.
Comment From: scordio
Done in fbbfe6ac8618c4e556b5d41f8e757584c459fbe7.