I'm using Spring Data 1.2.0.RELEASE. I'm using Spring Data's "custom implementation repository" functionality, as it is described here: http://static.springsource.org/sprin...mplementations
These are my interfaces and classes:
Code:interface UserRepositoryCustom { public void convertThenSave(LegacyUserClass legacyUser); }
Code:class UserRepositoryImpl implements UserRepositoryCustom { public void convertThenSave(LegacyUserClass legacyUser) { User convertedUser = convert(legacyUser); // now I would like to call UserRepository.save(convertedUser) ... } }As you can see in the above code, inside UserRepositoryImpl, I would like to call one of the CRUD methods inherited from CrudRepository. But because of the inheritance hierarchy as required by Spring Data's "custom implementation repository" functionality, this isn't possible.Code:public interface UserRepository extends CrudRepository<User, Long>, UserRepositoryCustom { // Declare query methods here }
What would be a good pattern that fulfills what I actually want to do?
My example use case of converting some legacy entity class to the repository's managed entity class may cause some people complain that a conversion service isn't the responsibility of a repository. But there are similar use cases, e.g. where one would like to delegate to the CrudRepository-provided methods from inside SomeRepositoryCustom to follow the DRY principle.


Reply With Quote
