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 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.