如何在springboot中Map实体类对象?

ghhkc1vu  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(354)

这是我的实体类,我正在使用它来保存客户的详细信息以及购买的详细信息和产品以及付款模块,它精细地保存在db中,但在检索结果时将其设置为null。

@Entity
@Table(name = "productpurchasedata")
public class Test {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int customerid;
    @ManyToOne(cascade = { CascadeType.ALL })
    @JoinColumn(name = "customerid", insertable = false, updatable = false)
    private CustomerProductSave customerProductSave;
    @ManyToOne(cascade = { CascadeType.ALL })
    @JoinColumn(name = "customerid", insertable = false, updatable = false)
    private PurchaseDetails purchasedetails;
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "customerid")
    private List<ProductPurchased> productpurchased;
    @ManyToOne(cascade = { CascadeType.ALL })
    @JoinColumn(name = "customerid", insertable = false, updatable = false)
    private PaymentHistory paymenthistory;

在这里,我可以保存数据,结果如下:-

{
    "customerid": 1,
    "customerProductSave": {
        "customerids": 2,
        "name": "nitesh",
        "mailid": "niteshbhushan95@gmail.com",
        "address": "hyd",
        "city": "telanagana",
        "state": "telanagana",
        "postalcode": "847226",
        "mobileno": 6300769631
    },
    "purchasedetails": {
        "purchasedate": "22-07-2021",
        "modeofpayment": "paytm",
        "emiapplicable": false,
        "totalamount": 21000,
        "purchaseId": 4
    },
    "productpurchased": [
        {
            "purchaseid": 5,
            "purchaseamount": 2000,
            "purchasedproductid": 1,
            "productquantity": 0
        },
        {
            "purchaseid": 6,
            "purchaseamount": 2000,
            "purchasedproductid": 1,
            "productquantity": 0
        }
    ],
    "paymenthistory": {
        "transactionid": 3,
        "paymentstatus": "paid"
    }
}

现在,当我试图通过customerid检索数据时,它不接受,它给出的消息为null,我不太可能是Map中的一些错误

wlp8pajw

wlp8pajw1#

尝试在所有Map中使用fetch=fetchtype.eager而不是fetch=fetchtype.lazy购买详细信息和购买的产品以及支付模块

相关问题