Spring Data jpa resouce mapping error "status":500,"error":"Internal Server Error",

I am trying to use pagination in my spring data jpa application. So from front (Angularjs) I have sent the following request:

.factory('InvoiceDetailsGeneralService', function ($http) {
        return {           
               
        findByInvoiceId: function (pageOff, pageLim , invoice) {  
        	console.log("Inv " + invoice.id);  
            return $http.get('/api/invoiceDetailss/byInvoiceId', {params: {page: pageOff.pageOffset, per_page: pageLim.pageLimit, invoiceId:invoice.id}}).then(function (response) {
                return response.data;
            });
        }
   
        };
    });

Open in new window


On the back end side in my Resource.java, I have,

@RequestMapping(value = "/invoiceDetailss/byInvoiceId",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE)
    @Timed
    public ResponseEntity<List<InvoiceDetails>> findByInvoiceId(@RequestParam(value="invoiceId") Long invoiceId,
    		@RequestParam(value = "page" , required = false) Integer offset,
            @RequestParam(value = "per_page", required = false) Integer limit )  throws URISyntaxException  {
        log.debug("REST request to get Invoice Details By Invoice Id " + invoiceId);
        Page<InvoiceDetails> page = invoiceDetailsService.findByInvoiceId(offset, limit, invoiceId);
        HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/invoiceDetailss/byInvoiceId", offset, limit);
        return new ResponseEntity<List<InvoiceDetails>>(page.getContent(), headers, HttpStatus.OK);        
     
    }

Open in new window


In service.java, i have

public Page<InvoiceDetails> findByInvoiceId(Integer offset, Integer limit, Long invoiceId) {
		// TODO Auto-generated method stub
		Pageable pageable = new PageRequest(offset, limit, Sort.Direction.ASC, "invoiceId");
		return invoiceDetailsRepository.findByInvoiceId(offset, limit, invoiceId, pageable);
	}

Open in new window


And in my repository I have,

public interface InvoiceDetailsRepository extends JpaRepository<InvoiceDetails,Long> {
		Page<InvoiceDetails> findByInvoiceId(Integer offset, Integer limit, Long invoiceId, Pageable pageable);
}

Open in new window



But in my browser I am getting the following error:

"NetworkError: 500 Internal Server Error - http://localhost:8080/api/invoiceDetailss/byInvoiceId?cacheBuster=1444676182224&invoiceId=1&page=1&per_page=20"

Open in new window


parameters are as follows in my browser console :
cacheBuster	1444676182224
invoiceId	 1
page	 1
per_page	 20

Open in new window


And the response is :

{"timestamp":1444676182364,"status":500,"error":"Internal Server Error","exception":"org.springframework
.dao.InvalidDataAccessApiUsageException","message":"Parameter value [1] did not match expected type 
[java.lang.Long (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [1] did
 not match expected type [java.lang.Long (n/a)]","path":"/api/invoiceDetailss/byInvoiceId"}

Open in new window


I am not sure where I am going wrong,  it seems that I have sent parameters correctly but it is showing error?
Too SmartAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
You can see by the exception message that the issue has nothing to do with the client side, the request it is sending, the "Resource" or even the "Service" layers. It is totally a Repository issue. I haven't done too much JPA work but I can at least tell you that you should start there. Set up a test case, without all the other stuff, that just tests your Repository setup, ie. set up the "invoiceDetailsRepository" object and call the "findByInvoiceId" method passing in some example test parameters and get that working.

If you do need more help then in resolving this, you will need to post the details of your Repository setup, etc.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gurpsbassiCommented:
As mccarl suggested, I think the problem is in here:

public interface InvoiceDetailsRepository extends JpaRepository<InvoiceDetails,Long> {
            Page<InvoiceDetails> findByInvoiceId(Integer offset, Integer limit, Long invoiceId, Pageable pageable);
}

Look at section 2.3 here: http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/jpa.repositories.html

It also describe how to do pagination.
0
Too SmartAuthor Commented:
As per suggestion, I was making trail and error and the function with the following syntax is working fine.

    Page<InvoiceDetails> findByInvoiceId(Long invoiceId, Pageable pageable);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.