簡體   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