The exception shows that when you try to save User it saves null as facilityId.
To make this work you need to specify the Facility as another table in User entity (you did it wrong way).
@Entity
@Table(name= "user_detail")
public class User {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
private String username;
@Column (name="contactNo")
private String contactNo;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "facilityId", referencedColumnName = "id")
private Facility facility;
//getter and setter
}
Based on your requirement you need to specify the relationship. It seems here that the relationship should be one to one so I marked it as such.
CLICK HERE to find out more related problems solutions.