相关文章推荐
活泼的木耳  ·  spring ...·  1 周前    · 
活泼的抽屉  ·  spring ...·  1 周前    · 
纯真的脸盆  ·  python中time.sleep用法 - ...·  2 月前    · 
帅气的钥匙扣  ·  python-docx 创建word ...·  4 月前    · 
善良的水煮鱼  ·  How to fix - Error 5: ...·  9 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams private Integer voteCount = 0; @ManyToOne(fetch = LAZY) @JoinColumn(name = "userId", referencedColumnName = "userId") private User user; @Column(name="created_date") private Instant createdDate; @ManyToOne(fetch = LAZY) @JoinColumn(name = "id", referencedColumnName = "id") private Sub sub; public Integer getVoteCount() { if (this.voteCount == null) { return 0; return this.voteCount;
//Repository
public interface PostRepository extends JpaRepository<Post, Long> {
    List<Post> findByOrderBycreateDateDesc();
    List<Post> findAllByDescriptionContaining(String description);
    List<Post> findAllByPostNameContaining(String postName);
    List<Post> findAllBySub(Sub sub);
    List<Post> findByUser(User user);
//Service
    @Transactional(readOnly = true)
    public List<PostResponse> getAllPosts() {
        return postRepository.findByOrderBycreateDateDesc()
                .stream()
                .map(postMapper::mapToDto)
                .collect(toList());

I'm using Java Spring Boot and Spring Data JPA I got some error like this

 Could not create query for public abstract java.util.List com.Website.Step2.repository.PostRepository.findAllOrderbycreateDateDesc()!
 Reason: Failed to create query for method public abstract java.util.List com.Website.Step2.repository.PostRepository.findAllOrderbycreateDateDesc()! 
 No property findAllOrderbycreateDateDesc found for type Post!

Can u guys help me! I think i was wrong in "findByOrderBycreateDateDesc". Thanks! Sorry for my english. This is the first time i post my question.xD

List<Post> findAllByOrderByCreatedDateDesc();

As it looks the table column name and the instance name are different therefore you have to annotate the instance variable as show below:

@Column(name="created_date")
                Thanks for your suggest but i tried it before ``` Failed to create query for method public abstract java.util.List com.Website.Step2.repository.PostRepository.findByOrderByCreateDateDesc()! No property createDate found for type Post! Did you mean 'createdDate'? ```
– Phạm Cường
                Mar 3, 2022 at 15:18
                Seems there is another typo. In the method you use "CreateDate" but the property is named "CreatedDate". I updated my answer.
– Jens Schauder
                Mar 4, 2022 at 7:24
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.