我有实体:
@Entity
@Table(name = "forum_comment", schema = "public")
public class ForumCommentEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne
@JoinColumn(name = "post", nullable = false)
private ForumPostEntity post;
@Column(name = "created", columnDefinition = "TIMESTAMP")
private LocalDateTime created;
}
我想找到属于论坛帖子的最新论坛评论。我有JpaRepository
:
public interface ForumCommentRepository extends JpaRepository<ForumCommentEntity, Long> {
long countByPost(ForumPostEntity entity);
LocalDateTime findAllByPostAndFindFirstByOrderByCreatedDesc(ForumPostEntity entity);
}
然而,它抱怨不知道FindFirst
等等。声明函数的正确方法是什么?首先按属性过滤,然后对它们进行排序,只返回最新的行。
感谢您的帮助!
1条答案
按热度按时间nnt7mjpx1#
您必须在开头移除findAll。它必须是:
findFirstByPostOrderByCreatedDesc