have gotten into the field after time away and working on getting up to speed with my java skills using the spring framework using spring boot and spring data jpa.
Here is my issue....I have a project management application that I am developing, the main table, called project who has a foreign key to a static status table and when trying to insert a new project entity to the database with the status table object set, I either get duplication of status' in the status table or as in the current form, error with it trying to insert a new status record in the database with error on foreign key restraint.
How do I map this relationship so that the project is saved without creating a new status record? Or do I just need to remove constraint of project and status table and at the object level save the id of the status with the project entity?
Project Entity Class
@Entity
@Table(name = "project_tbl")
public class Project implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
//Name and date fields ommited
@ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST)
@JoinColumn(name = "status_id")
private ProjectStatus status;
//Constructors, getters and settings ommited
Status Entity Class
@Entity
@Table(name = "status_tbl")
public class ProjectStatus implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String name;