For Spring MVC application as ORM jpa with hibernate was configured. Every request will be in usual form submit and response will be json so configured Jackson Json and used @ResponseBody . Everything was working fine except one Many to One mapping for a entity.
public class Supplier implements BaseEntity{
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer id;
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "bank_id", nullable = false)
private Bank bank;
/*
all getters and setters
*/
}
Bank entity
@Entity
@Table(name="bank_tbl", uniqueConstraints=@UniqueConstraint(columnNames="name_bank"))
public class Bank implements BaseEntity{
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name="bank_id")
private Integer id;
@Column( nullable=false)
private String name;
@Column(name="desc_bank", columnDefinition="TEXT")
private String desc;
/*
all getters and setters
*/
}
Sample Request
id:1 name:"Steve" bank:4
First confusion is how to bind the bank id value present in request to entity. Secondly after binding wether to do any special way to presist the Supplier entity other than entityManager.merge(supplier); . How to retrive the Supplier json with only bank_id . Is entity itself need to be change to fulfill this requirement?