1

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?

Francis Zabala
  • 1,037
  • 2
  • 11
  • 30
  • do you need to create the merchant too? – skioppetto Oct 22 '15 at 07:40
  • no, the merchant already exists. – Francis Zabala Oct 22 '15 at 07:50
  • Is your repository a `CrudRepository`? What exactly do you want to do, Insert a record inside Merchant Detail table? – prettyvoid Oct 22 '15 at 07:54
  • Yeah it is a CrudRepository. Well, I have a rest endpoint that accepts json and, map it to an object using Jackson and save it using CrudRepository. And you are correct, I am trying to save a new record inside the merchantdetail table – Francis Zabala Oct 22 '15 at 07:59
  • try this: @JoinColumn(referencedColumnName="merchantId", insertable=false, updatable=false) and add a new property `String merchantId` setting the right column name. The json will contain the field merchantId equals to the the merchant key... even if I suggest you to never map directly ORM to exposed objects – skioppetto Oct 22 '15 at 10:12
  • Does this mean that I will have to remove the getter/setter for the reference object as per answer here? http://stackoverflow.com/questions/15076463/another-repeated-column-in-mapping-for-entity-error – Francis Zabala Oct 22 '15 at 11:30

0 Answers0