spring data - get beans in a custom default repository implementation

83 Views Asked by At

Im trying to upgrade my project from spring-boot-1.4.3.RELEASE to spring-boot-1.5.9.RELEASE.

In the 1.4.3.RELEASE the way I have used my custom implementation of repositories is as follow:

  1. Made an interface MyCustomRepositroy that extends JpaRepository
  2. Had a class MyCustomRepositoryImpl that implements MyCustomRepositroy and SimpleJpaRepository. In that class I have changed the behavior of
    the of save, find and delete methods, because I needed a
    ceratin behavior for entitys of certain type (lets say that I need a custom save for all entitys that implements Special interface)
  3. I made a MyCustomJpaRepositoryFactoryBean that extends JpaRepositoryFactoryBean. In that factory, I've overridden createRepositoryFactory and gave it my MyRepositoryFactory implementation. In MyRepositoryFactory implementation I've overridden the getTargetRepository, and getRepositoryBaseClass.In these methods, I check if the entity is of type Special, and if so, I return MyCustomRepositoryImpl, otherwise I return SimpleJpaRepository.

Also, I can get the beanFactory in my MyCustomRepositoryImpl class because I call my own constructor of MyCustomRepositoryImpl that has also a beanFactory parameter via getTargetRepositoryViaReflection.

Now, with the new version (that uses spring-data-commons-1.13.9.RELEASE), I cannot override the Factory class, and hence can't decide for each entitiy which implementation to give, and have no way to get the beanFactory.

Is there any way I can get what I want?

Sorry for the mess, but I cannot post my code here.

P.S - my project is a spring based library, so I can't do anything to the entitys because my clients declare them, all I know that some entitys implement the Special interface and some don't

1

There are 1 best solutions below

0
On

I am trying to figure out what happened in 1.5.9.RELEASE, but in the meantime, just as a fyi - 1.5.6.RELEASE works ok.

I am having the same issue when trying to update from 1.5.6.RELEASE to 1.5.9.RELEASE