I have a below table having entries in 1NF form. product_category column is haven redundant entries.
Columns:
product_name varchar(1000)
product_category varchar(100)
description varchar(2000)
product_id int AI PK
product_image_url varchar(1000)
product_price int
Entries Example:
salaryCard, Mastercard, Salary Card Description, 553535hhfsf7s4w, null, 134353
businessCard, Mastercard, Business Card Description, 553534654fgf4w, null, 134353
salaryCard, VISA, Salary Card Description, 55f453rwrfsf7s4w, null, 134353
businessCard, VISA, Business Card Description, 553fdasa2434fgf4w, null, 134353
I want below nested JSON for above queries.
{"Mastercard":[{"productName":"salaryCard","description":"Salary Card Description","productId":"553535hhfsf7s4w","productUrl":null,"productPrice":134353},{"productName":"businessCard","description":"businessCard Card Description","productId":"553534654fgf4w","productUrl":null,"productPrice":134353}],"VISA":[{"productName":"salaryCard","description":"Salary Card Description","productId":"553535hhfsf7s4w","productUrl":null,"productPrice":134353},{"productName":"businessCard","description":"businessCard Card Description","productId":"553534654fgf4w","productUrl":null,"productPrice":134353}]}
How can I create an Entity and how can I write a JPA query to fetch the records in above format.
question from:
https://stackoverflow.com/questions/65884601/how-to-get-nested-json-by-using-spring-boot-jpa-from-single-table-based-on-categ