1

I have a domain class called StoreType.java which is exposed by below spring repository

public interface StoreTypeRepository extends PagingAndSortingRepository<StoreType, Short> {

}

When I access this using url http://localhost:8080/my-persistence/jpa/storetypes it returns 404.

if I change my domain class as Storetype (without camel case), it works fine and return 200 OK.

I have few more repositories which uses single world domain classes like Store.java , Country.java and these work fine and by default these exposed as plural of domain class name.

I know spring exposed url as plural of domain classes but not sure why it is not exposing it. I can override this using @RepositoryRestResource(path="/storetypes") but I want to know what is default rest url if domain classes name in camel case.

Vijay Kumar Rajput
  • 1,071
  • 1
  • 10
  • 30

1 Answers1

1

You seem to have answered the question to your problem by specifying the @RepositoryRestResource( path="/storetypes" ) annotation as the documentation states.

Spring Data REST exposes a collection resource named after the uncapitalized, pluralized version of the domain class the exported repository is handling. Both the name of the resource and the path can be customized using the @RepositoryRestResource on the repository interface.

In this case your naming convention seems correct using StoreTypeRepository however one thing confuses me about your repository definition... I'm not sure why you set the type parameter to the PagingAndSortingRepository<StoreType, Short> but I'm quite certain that's incorrect as the second type parameter should be of type Long.

Edward J Beckett
  • 5,061
  • 1
  • 41
  • 41
  • Yes you are correct, since I have already added path=/storetypes, so my issue is resolve, but my question was that what should be the default path generated by spring if I have repository like StoreType with camel case.If I don't use camel case then it works as you said. – Vijay Kumar Rajput Oct 30 '14 at 05:43
  • I have defined short as type because I know my stores can''t grow more then 32767 which is mysql smallint and represented in java as short. SMALLINT in mysql is 2 bit and if I go for BINGINT then its 8 bit. – Vijay Kumar Rajput Oct 30 '14 at 05:51
  • Well I guess that's okay. I'm still rather baffled why your class doesn't work with a camelcase class name. You may have discovered a bug. You might try submitting a bug to the tracker for [spring data](https://jira.spring.io/browse/DATAREST). – Edward J Beckett Oct 30 '14 at 20:57
  • 1
    Thanks Eddie. I have open a bug under spring data rest. https://jira.spring.io/browse/DATAREST-402 – Vijay Kumar Rajput Oct 31 '14 at 05:12
  • 1
    `storeTypes` *is* the capitalized, pluralized version of `StoreType` :) – Oliver Drotbohm Oct 31 '14 at 07:28