[英]How to map the entity class object in springboot?
This is my entity class , which I am using to save the details of customer along with the purchase detail and product purchased and payment module , Its finely saving in DB but while retrieving getting result as null .这是我的实体类,我用它来保存客户的详细信息以及购买的详细信息和购买的产品以及付款模块,它很好地保存在数据库中,但检索结果为 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;
Here I am able to save the data which result in something like this :-在这里,我可以保存导致如下结果的数据:-
{
"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"
}
}
Now when I am trying to retrieve the data by customerid it is not accepting , it giving message as null , I am not pretty much may be some mistake in mapping现在,当我尝试通过 customerid 检索数据时,它不接受,它将消息显示为 null ,我不太可能在映射中出现一些错误
尝试使用 fetch = FetchType.EAGER 而不是 fetch = FetchType.LAZY 在所有映射购买细节和产品购买和支付模块
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.