Open federicotg opened 6 months ago
There's a workaround.
Don't use @EnableEnversRepositories
, just keep @EnableJpaRepositories
and define manually each RevisionRepository like this
public @Bean
RevisionRepository<MyEntity, Integer, Long> myEntityRevisions() {
final JpaEntityInformation<MyEntity, ?> entityInformation = JpaEntityInformationSupport.getEntityInformation(MyEntity.class, entityManager);
final RevisionEntityInformation revisionEntityInformation = new ReflectionRevisionEntityInformation(MyCustomRevision.class);
return new EnversRevisionRepositoryImpl<>(entityInformation, revisionEntityInformation, entityManager);
}
or like this:
public @Bean
RevisionRepository<MyEntity, String, Integer> myEntityRevisionRepository() {
final JpaEntityInformation<MyEntity, ?> entityInformation = JpaEntityInformationSupport.getEntityInformation(MyEntity.class, entityManager);
final RevisionEntityInformation revisionEntityInformation = new DefaultRevisionEntityInformation();
return new EnversRevisionRepositoryImpl<>(entityInformation, revisionEntityInformation, entityManager);
}
As explained here:
Alternative, your can create two different repository and configure annotation @EnableJpaRepositories
and @EnableEnversRepositories
like annotation filter or use different package
@HistoryRepository
public interface MyEntityHistoryRepository extend RevisionRepository<MyEntity, Long, Long> {}
and
public interface MyEntityRepository extend JpaRepository<MyEntity, Long> {}
configure JpaRepository
@Configuration
@EnableJpaRepositories(excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = HistroyRepository.class))
public class JpaConfiguration {}
configure EnversRepository
@Configuration
@EnableEnversRepositories(includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = HistroyRepository.class))
public class JpaHistoryConfiguration {}
Or you can create custom repository factory bean like this
What steps will reproduce the problem ?
Steps to reproduce the behavior:
What is the expected output ?
Spring context should start and the Envers repositories should work normally.
What happens instead ?
Spring context fails to start.
Environment
Additional context
The problem is @EnableEnversRepositories uses its own repositoryFactoryBeanClass that is EnversRevisionRepositoryFactoryBean and EntityGraphJpaRepositoryFactoryBean does not extend that one. I can't create my own EnversRevisionRepositoryFactoryBean subclass adding the RepositoryEntityManagerEntityGraphInjector because it is package private. Envers is a popular hibernate audit log implementation and spring-data-envers is a spring-data module to deal with envers in a spring-data way.