I am trying to map an array of Objects to a field. All the fields in that object are being mapped to columns with different name but similar structure. The response structure should be:
"customers": [
{
"firstName": "string",
"lastName": "string",
"products": [
{
"description":"string",
"amount": "string"
},
{
"description":"string",
"amount": "string"
}
]
}
]
Inside the products field, I have a list of product(description and amount). In DB, columns are stored like
product_des1,product_amt1,product_des2,product_amt2.....product_des30,product_amt30
. I need to map these two fields to the product(object). How should I approach to solve the problem using JPA annotations if possible?
For the reference: Customers.class
@Entity
public class Customers implements Serializable {
@Column(name = "firstName")
private String firstName;
@Column(name = "lastName")
private String lastName;
@ElementCollection
List<Products> products;
}
Product.class
@Embeddable
public class Product implements Serializable {
@Column(?)
private String description;
@Column(?)
private String amount;
}
@ManyToManyrelationship. This is currently not possible