Announcement Announcement Module
No announcement yet.
How to expose count method in JPA repository as REST API call using spring data rest. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to expose count method in JPA repository as REST API call using spring data rest.

    I am learning the Spring-Data-Rest and trying to add the countBy*** functionality in my Customer Repository and expose it as REST API. However, when I try to make the api call (http://localhost:8080/customers/sear...firstname=Dave, or http://localhost:8080/customers/search/countByFirstname?firstname=Dave), I get 500 Internal Server Error
    Below is how my repository looks like, Any input shall be much appreciated.

    public interface CustomerRepository extends JpaRepository<Customer, Long>{ Customer findByEmailAddress(@Param("emailAddress") EmailAddress emailAddress); @Query("select c from Customer c where c.firstname = :firstname") Customer findByFirstNameUsingQuery(@Param("firstname") String firstname); public long countByFirstname(@Param("firstname") String firstname); @Query("select count(c) from Customer c where c.firstname = :firstname") Long countByFirstnameUsingQuery(@Param("firstname") String firstname); } Below is my Customer class

    @Entity public class Customer extends AbstractEntity { private String firstname, lastname; @Column(unique = true) private EmailAddress emailAddress; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "customer_id") private Set<Address> addresses = new HashSet<Address>();
    There is no exception coming on the server logs. Below is all what comes to the server logs However, below is what comes to the logs. 2014-05-08 13:02:05,551 DEBUG rest.webmvc.RepositoryRestHandlerMapping: 219 - Looking up handler method for path /customers/search/countByFirstname 2014-05-08 13:02:05,567 DEBUG rest.webmvc.RepositoryRestHandlerMapping: 226 - Returning handler method [public org.springframework.http.ResponseEntity> rchController.executeSearch(org.springframework.da,org.springf ramework.web.context.request.WebRequest,java.lang. String,