Rest API and Hibernate. How to add a new record with foreign key?

岁酱吖の 提交于 2019-12-24 11:57:11

问题


I have this object:

public class MerchantDetail {

    private id;
    private boolean optStatus;
    private BigDecimal amountDue;


    @ManyToOne(optional=false) 
    @JoinColumn(referencedColumnName="merchantId") 
    private Merchant merchant;

    //getters and setters
}

My table looks like this:

`MerchantDetail` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`amountdue` decimal(19,2) DEFAULT NULL,
`optstatus` BIT() DEFAULT NULL,
`merchant_merchantId` varchar(255) NOT NULL //autogenerated by hibernate
)

My current codes are using Spring Data JPA using Hibernate.

My Rest API is using Jersey for endpoints and Jackson for marshalling and unmarshalling data.

How am I going to create a new record using JSON?

来源:https://stackoverflow.com/questions/33275538/rest-api-and-hibernate-how-to-add-a-new-record-with-foreign-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!