Announcement Announcement Module
No announcement yet.
How to use Repository methods inside a custom Repository implementation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use Repository methods inside a custom Repository implementation

    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 when the Record has been set up. Based on the documentation, I am trying to do something like this:

    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;
         return record;
    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.

    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?

    - David.

  • #2
    I tried to create an aspect which modifies the CreateRecordRepository interface that includes the desired create method, but the aspect doesn't seem to work, throwing a "Failed to load ApplicationContext" exception, probably because no implementation for CrateRecordRepository is ever actually created for the aspect to weave into.

    Anyone have any suggestions on this?

    - David.