Replies: 3 comments 1 reply
-
Hi @sanemain , This library repository factory bean currently looks like this: public class EntityGraphJpaRepositoryFactoryBean<
R extends Repository<T, I>, T, I extends Serializable>
extends JpaRepositoryFactoryBean<R, T, I> {
/**
* Creates a new {@link JpaRepositoryFactoryBean} for the given repository interface.
*
* @param repositoryInterface must not be {@literal null}.
*/
public EntityGraphJpaRepositoryFactoryBean(Class<? extends R> repositoryInterface) {
super(repositoryInterface);
}
@Override
public void setEntityManager(EntityManager entityManager) {
/* Make sure to use the EntityManager able to inject captured EntityGraphs */
super.setEntityManager(RepositoryEntityManagerEntityGraphInjector.proxy(entityManager));
}
@Override
protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
return new EntityGraphJpaRepositoryFactory(entityManager);
}
} IMO, the easiest and most naive solution would be to copy its content to your own RepositoryFactoryBean like this: public class MyCustomRepositoryFactoryBean<
R extends Repository<T, I>, T, I extends Serializable>
extends DataTablesRepositoryFactoryBean<R, T, I> {
public EntityGraphJpaRepositoryFactoryBean(Class<? extends R> repositoryInterface) {
super(repositoryInterface);
}
@Override
public void setEntityManager(EntityManager entityManager) {
super.setEntityManager(RepositoryEntityManagerEntityGraphInjector.proxy(entityManager));
}
@Override
protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
return new EntityGraphJpaRepositoryFactory(entityManager);
}
} Notice that the only difference is that this custom implementation extends @Configuration
@EnableJpaRepositories(repositoryFactoryBeanClass = MyCustomRepositoryFactoryBean.class)
public class MyConfiguration {} I think a more elegant solution would require to discuss this with the Spring Data team. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response @reda-alaoui . I am not sure if I understood your solution, public class CustomRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements
EntityGraphJpaRepository<T, ID>, EntityGraphJpaSpecificationExecutor<T>, DataTablesRepository<T, ID> {
private EntityGraphJpaRepository<T, ID> entityGraphRepository;
private DataTablesRepository<T, ID> dataTablesRepository;
public CustomRepositoryImpl(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
super(entityInformation, entityManager);
}
@Override
public Page<T> findAll(Pageable pageable, EntityGraph entityGraph) {
return entityGraphRepository.findAll(pageable, entityGraph);
}
//.....
@Override
public DataTablesOutput<T> findAll(DataTablesInput input) {
return dataTablesRepository.findAll(input);
}
//.....
} This is not enough for sure, I also need to create a new |
Beta Was this translation helpful? Give feedback.
-
Yes you are correct, I missed this part. The solution is now very britle.
I'd like to avoid turning those classes into public classes :/ |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am already using another spring data JPA extension in my project, the library is hosted at this address if anyone is interested: https://github.com/darrachequesne/spring-data-jpa-datatables.
Is it possible to use jpa-entity-graph in conjunction with the other library?
Beta Was this translation helpful? Give feedback.
All reactions