Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom jpa repository method published by spring-data-rest

I've added a custom method to a jpa repository as detailed on http://docs.spring.io/spring-data/data-jpa/docs/1.0.x/reference/html/#repositories.custom-implementations

As far as I could see, this method is not exposed when I use spring-data-rest. Is there any way I could publish it as part of the REST API generated by spring-data-rest (without creating a Spring MVC Controller myself)?

like image 393
Andres Avatar asked Jan 14 '14 14:01

Andres


People also ask

Which method is used to fetch all rows in Spring data JPA repository?

I can use the findAll() method to select * from my_table to get all columns and rows.


1 Answers

I checked the code base - seems like they have explicitily disabled custom methods - not sure why. Here is the relevant piece of code from org.springframework.data.repository.core.support.DefaultRepositoryInformation

@Override
public Set<Method> getQueryMethods() {

    Set<Method> result = new HashSet<Method>();

    for (Method method : getRepositoryInterface().getMethods()) {
        method = ClassUtils.getMostSpecificMethod(method, getRepositoryInterface());
        if (isQueryMethodCandidate(method)) {
            result.add(method);
        }
    }

    return Collections.unmodifiableSet(result);
}

/**
 * Checks whether the given method is a query method candidate.
 * 
 * @param method
 * @return
 */
private boolean isQueryMethodCandidate(Method method) {
    return isQueryAnnotationPresentOn(method) || !isCustomMethod(method) && !isBaseClassMethod(method);
}
like image 144
Faisal Feroz Avatar answered Sep 29 '22 11:09

Faisal Feroz