Announcement Announcement Module
Collapse
No announcement yet.
findAll without where condition but with OrderBy doesn't work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • findAll without where condition but with OrderBy doesn't work

    Any idea why List<Post> findAllOrderByTitleAsc(); doesn't work?
    List<Post> findAllByIdGreaterThanOrderByTitleAsc(Long id); works well

    Here the error
    Caused by: org.springframework.data.mapping.PropertyReference Exception: No property asc found for type java.lang.String
    at org.springframework.data.mapping.PropertyPath.<ini t>(PropertyPath.java:74) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.crea te(PropertyPath.java:326) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.crea te(PropertyPath.java:306) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.crea te(PropertyPath.java:329) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.crea te(PropertyPath.java:352) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.crea te(PropertyPath.java:306) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.from (PropertyPath.java:270) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.from (PropertyPath.java:244) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.repository.query.parser.P art.<init>(Part.java:73) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.repository.query.parser.P artTree$OrPart.<init>(PartTree.java:180) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.repository.query.parser.P artTree$Predicate.buildTree(PartTree.java:260) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.repository.query.parser.P artTree$Predicate.<init>(PartTree.java:240) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.repository.query.parser.P artTree.<init>(PartTree.java:71) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.Part TreeJpaQuery.<init>(PartTreeJpaQuery.java:57) ~[spring-data-jpa-1.2.0.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQ ueryLookupStrategy$CreateQueryLookupStrategy.resol veQuery(JpaQueryLookupStrategy.java:90) ~[spring-data-jpa-1.2.0.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQ ueryLookupStrategy$CreateIfNotFoundQueryLookupStra tegy.resolveQuery(JpaQueryLookupStrategy.java:162) ~[spring-data-jpa-1.2.0.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQ ueryLookupStrategy$AbstractQueryLookupStrategy.res olveQuery(JpaQueryLookupStrategy.java:68) ~[spring-data-jpa-1.2.0.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.R epositoryFactorySupport$QueryExecutorMethodInterce ptor.<init>(RepositoryFactorySupport.java:280) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.R epositoryFactorySupport.getRepository(RepositoryFa ctorySupport.java:148) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.R epositoryFactoryBeanSupport.getObject(RepositoryFa ctoryBeanSupport.java:125) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.R epositoryFactoryBeanSupport.getObject(RepositoryFa ctoryBeanSupport.java:41) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
    at org.springframework.beans.factory.support.FactoryB eanRegistrySupport.doGetObjectFromFactoryBean(Fact oryBeanRegistrySupport.java:142) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    ... 49 common frames omitted
    Last edited by niels; Mar 25th, 2013, 05:39 AM. Reason: Mark as question.

  • #2
    I too am having this problem. I even tried using Spring-Data-JPA 1.4.0.M1 and Spring-Data-Commons 1.6.0.M1. Does anyone have a fix or workaround? TIA

    Comment


    • #3
      The quick solution I found to define findAll in the Repository interface like this:
      List <myClass> findAll(Sort sort) throws DataAccessException;

      Then in the class that uses the repository:
      @Autowired
      Repository repo;

      someMethod(){
      repo.findAll(new Sort(new Sort.Order(Sort.Direction.ASC,"title")));
      }

      This will work, but the repository should be able to use findAllOrderByTitleAsc(). And thank you Spring Data team for all your hard work!

      Comment

      Working...
      X