繁体   English   中英

JPA 存储库 findAll 返回空列表

[英]JPA Repository findAll returns empty list

我试图从数据库中获取一个列表,而 findAll() 返回空列表。 我有多个 jpa 存储库,但只有一个不起作用。 这是代码:

@Repository
public interface ProductCategoryRepository extends JpaRepository<ProductCategory,Integer> {
}

这是实体:

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductCategory {
    @Id
    private Integer id;
    private String name;
    private String description;

    @OneToMany(fetch = FetchType.EAGER,mappedBy = "productCategory", cascade = CascadeType.ALL)
    @JsonIgnore
    private List<Product> products = new ArrayList<>();
}

当我调用 productCategoryRepository.findAll() 时,它返回空列表,因此我在数据库中有很多条目。 谢谢你的帮助!

我遇到了同样的问题,我解决了生成 getter 和 setter 的问题,因为我没有配置我的 lombok

您可以将@Column注释添加到字段(ID除外)并尝试吗? 希望它能起作用。如果您仍然没有结果,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM