Announcement Announcement Module
Collapse
No announcement yet.
How do you add custom method impls to all repositories & specific ones? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do you add custom method impls to all repositories & specific ones?

    Consider the following custom repository interface:
    Code:
    @NoRepositoryBean
    public interface CustomRepository<T, ID extends Serializable>
        extends JpaRepository<T,ID> {
    
        void doSomethingInteresting(); // common to all repositories
    }
    Its implementation:
    Code:
    public class SimpleJpaCustomRepository<T, ID extends Serializable>
        extends SimpleJpaRepository<T,ID> {
    
        public void doSomethingInteresting() { /* ... */ }
    }
    Another custom repository interface:
    Code:
    public interface FooRepository
        extends CustomRepository<Foo,Long> {
    
        List<Foo> findByBarLike(String criteria); // SD JPA dynamic finder
    
        List<Foo> findByBarStartingWith(String criteria); // my own finder
    }
    Now, if the implementation of findByBarStartingWith is
    Code:
    public List<Foo> findByBarStartingWith(String criteria) {
    
        String intendedCriteria = criteria.replace("_", "\\_").replace("%", "\\%") + "%";
    
        return findByBarLike(intendedCriteria); // from SD JPA via "this"?
    }
    in what class do I put this method yet still have SD JPA provide an implementation of findByBarLike? Would it be available via this or some other reference? How would I configure this in my Spring context?
Working...
X