I dont know how to ask this question, but hope my explanation help
My issue is getting this result:
[
{
"product_id": 30001,
"product_name": "shoe",
"product_price": 40.5,
"product_description": "for gym",
"seller": {
"seller_id": 20001,
"seller_name": "cindi",
"seller_email": "cindi2@gmail.com",
"seller_pswd": "abc123",
"seller_contact": "92212152",
"seller_wallet": 456
}
},
{.....
But I want to return like this (direct fetch from mysql ) when i fetch from spring:
Model for product:
@Entity
@Data
@SequenceGenerator(name="seq", initialValue=3000, allocationSize=1)
public class Product {
@Id
private int product_id;
private String product_name;
private BigDecimal product_price;
private String product_description;
@ManyToOne
@JoinColumn(name = "seller_id")
private Seller seller;
@JsonIgnore
@ManyToMany(mappedBy = "products")
private Set<Cart> cart;
}
Model for seller:
@Entity
@Data
@SequenceGenerator(name="seq", initialValue=2000, allocationSize=1)
public class Seller {
@Id
private int seller_id;
private String seller_name;
private String seller_email;
@Size(min=5, message = "Password must contain atleast 8 character")
@NotNull(message = "Password cannot be blank")
private String seller_pswd;
private String seller_contact;
@JsonIgnore
@OneToMany(mappedBy = "seller")
private Set<Product> product;
}
Is there any way to make it return the same as my actual db? or should i just remove all the mappings in the Model?
and since we are asking about model mapping, (onetoone, manytomany, etc...,) is there any benefit to it for my case - a seller info need to be in the table before adding products, and after that products can be add any time, many times after that.
i dont need to add a seller with many products in 1 go, which to my undersrtanding which is why this mappings are essential IF that is for my case. but for my case, do i really need to do mapping? i feel like removing all mappings and just create relationship thru table creation directly at in the db.
not sure which one