带有orderBy的Spring-JPA命名查询不';行不通

带有orderBy的Spring-JPA命名查询不';行不通,spring,spring-boot,spring-data-jpa,spring-data,Spring,Spring Boot,Spring Data Jpa,Spring Data,我使用的是SpringBoot2、SpringJPA和SpringData 我试图从一个表中获取第一个结果,在这个表中,我想按int属性asc对结果进行排序 这是我的豆子: @Entity public class DatabaseInstance extends AbstractEntity { @NotNull @Enumerated(EnumType.STRING) @Column(nullable = false) private Supplier su

我使用的是SpringBoot2、SpringJPA和SpringData

我试图从一个表中获取第一个结果,在这个表中,我想按int属性asc对结果进行排序

这是我的豆子:

@Entity
public class DatabaseInstance extends AbstractEntity {

    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private Supplier supplier;

    NotNull
    @Column(nullable = false, columnDefinition = "INT DEFAULT 0.0")
    private int databaseCount = 0;
这是我的存储库:

@Transactional
public interface DatabaseInstanceRepository extends JpaRepository<DatabaseInstance, Long> {

    public Optional<DatabaseInstance> findFirstOrderByDatabaseCountAsc();

}

我无法找出我的方法名有什么问题。有什么建议吗?

试试
findFirstByOrderByDatabaseCountAsc()
它能用@RanjeetWould如果您只使用JpaRepository的分页和排序的“findAll(Pageable)”方法就好了,该方法可以在所有情况下使用,有顺序与否,第一个或更多结果。只需通知您排序属性和页面大小1。
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property asc found for type int! Traversed path: DatabaseInstance.databaseCount.