I am trying to implement a custom repository method for a spring data repository.
Trying to add a custom create method to my RecordRepository which handles does some work to create a Record before saving it to the database. Therefore, I want to call RecordRepository.save() when the Record has been set up. Based on the documentation, I am trying to do something like this:
I don't see how to make the save call. I don't have a reference to a RecordRepository and it can't be injected either.Code:public interface CreateRecordRepository { Record create(String name); } public interface RecordRepository extends PagingAndSortingRepository<Record, String>, CreateRecordRepository { ... } public class CreateRecordRepositoryImpl implements CreateRecordRepository { public Record create(String name) { // do some stuff Record record = ... // make a call to the save function of RecordRepository recordRepository.save(record); return record; } }
I know I could create a separate class that has the repository injected into it, but I think it makes sense to have this method in the repository itself.
Any suggestions?
Thanks,
- David.


Reply With Quote
