I did a small application with more relationships. Now I want to delete details of my table how can I delete I don't get any Idea to delete.
Relationships are like below:
PanCard-->Employee (Ono To One)
Employee-->ProjectManger (bi-directional many-to-one association to Employee)
Projects -->ProjectManager(bi-directional many-to-one association to Projects)
Now I want delete the data of one by one table data
Below is my POJO classes Code:
PanCard.java
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int id;
@Column(name="pName")
private String pName;
@Column(name="pNumber")
private int pNumber;
@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@JoinColumn(name="EId")
private Employee employee;
Employee.java
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "empFirstName")
private String empFirstName;
@Column(name = "empLastName")
private String empLastName;
@Column(name = "empDepartment")
private String empDepartment;
@ManyToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="pmId")
private ProjectManager projectManager;
ProjectManager.java
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String department;
private String managerFirstName;
private String managerLastName;
//bi-directional many-to-one association to Myemployee
@OneToMany(mappedBy="projectManager",cascade = CascadeType.ALL)
private List<Employee> employee;
@OneToMany(mappedBy="projectManager",cascade = CascadeType.ALL)
private List<Projects> projects;
Projects.java
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int id;
@Column(name="projectName")
private String projectName;
@Column(name="projectDesc")
private String projectDesc;
@ManyToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="pmId")
private ProjectManager projectManager;
Now I want delete the tables data: From which table I should start deletion.
- If I want to delete
Pancard
I should deleteProjectManager
becauseEmployee
have FK. - If I want to delete
ProjectManager
it should delete theEmployee
andProjects
butEmployee
have relationship withPanCard
So it's not deleting. - If I want to delete
Projects
it should deleteProjectManager
butProjectManger
have relation ship withEmployee
So it's not deleting.
So from where I have to start deletion and how can I delete the I don't know.