使用Hibernate将嵌套的JSON数据保存到MySQL数据库中

使用Hibernate将嵌套的JSON数据保存到MySQL数据库中,第1张

使用Hibernate将嵌套的JSON数据保存到MySQL数据库中

注释中所述,您可以按以下方式修改代码以使其按预期工作。

MarketPrice.java

@Entity@Table(name = "MarketPrice")public class MarketPrice {@Id@GeneratedValue(strategy = GenerationType.AUTO)@Column(name = "itemId")private Long itemId;@Column(name = "analysisDate")private Date analysisDate;@Column(name = "marketName")private String marketName;@Column(name = "category")private String category;@Column(name = "marketPlace")private String marketPlace;@Column(name = "state")private String state;@Column(name = "district")private String district; @Transient public Items currentItem;@Column(name = "itemName")public String getItemName() {    return this.currentItem.itemName;}@Column(name = "unitofPrice")public String getUnitofPrice() {    return this.currentItem.unitofPrice;}@Column(name = "minimumPrice",columnDefinition = "Float(10,2)")public Float getMinimumPrice() {    return this.currentItem.minimumPrice;}@Column(name = "maximumPrice",columnDefinition = "Float(10,2)")public Float getMaximumPrice() {    return this.currentItem.maximumPrice;}@Transientpublic ArrayList<Items> marketPrices;

Items.java

public class Items implements Serializable {    private static final long serialVersionUID = -2428562977284114465L;    @Id    @Column(name="id")    private int id;    public String itemName;    public String unitofPrice;    public Float minimumPrice;    public Float maximumPrice;

DAO.java

public String saveListOfMarketPrice(MarketPrice marketPrice) {        System.out.println("In Analyser DAO fro bulk saving");        final Session session = getSession();        session.beginTransaction();        for (Items item : marketPrice.marketPrices) {marketPrice.currentItem = item;session.save(marketPrice);        }        session.getTransaction().commit();        session.close();        return "success";    }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5442601.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存