I want to have a repository for entities (regular JPA repository) as well as a separate repository that keeps track of audit information (a RevisionRepository, part of hibernate envers).
I cannot seem to get this to work in my application.
As far as I can understand, each type of repository needs to be instantiated with it's own factory (JpaRepository with repositoryFactoryBeanClass
, and RevisionRepository
with EnversRevisionRepositoryFactoryBean
), and that can be set with the @EnableJpaRepositories
annotation.
The issue is that only one of that annotation can be on my main class. I have seen an example of this being done in xml form (here), but I don't know how to do this with annotations.
How can this be done?
The
EnversRevisionRepositoryFactoryBean
extends theJpaRepositoryFactoryBean
so you should only have to specify theEnversRevisionRepositoryFactoryBean
in your configuration to get both to work for you.What happens internally is that if the
EnversRevisionRepositoryFactoryBean
determines that your repository does not implement the the correct interface, it will delegate to the super implementation, which in this case is theJpaRepositoryFactoryBean
.