@Entity
@Table(name = "service_staff")
public class ServiceStaff implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@JoinColumn(name = "service_id", referencedColumnName = "id", nullable = false)
@OneToOne(optional = false)
private Service serviceId;
@JoinColumn(name = "user_id", referencedColumnName = "id", nullable = true)
@OneToOne(optional = true)
private User userId;
@JoinColumn(name = "designation_id", referencedColumnName = "id", nullable = true)
@OneToOne(optional = true)
private Designation designationId;
@Column(name="head")
private boolean head;
@Column(name="head_type")
private int headType;
.......
}
@Entity
@Table(name = "project_staff")
public class ProjectStaff implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@JoinColumn(name = "project_id", referencedColumnName = "id", nullable = false)
@OneToOne(optional = false)
private Project projectId;
@JoinColumn(name = "user_id", referencedColumnName = "id", nullable = true)
@OneToOne(optional = true)
private User userId;
@JoinColumn(name = "designation_id", referencedColumnName = "id", nullable = true)
@OneToOne(optional = true)
private Designation designationId;
@Column(name="head")
private boolean head;
@Column(name="head_type")
private int headType;
.......
}
Above are some of the data tables on my project where I want to find the remaining list of data from 'ServiceStaff' model class which are not exist on ProjectStaff class. Here in ServiceStaff data the staff may be of type User/Designation/Head where Designation & Head has a headType with value 1 for 'Main' and value 2 for 'Assistant'.How can I fetch the result as below using Hibernate with minimum load in my java code. Do I need to use any join to make it easy? Please excuse for the way I described it here since, I didn't find any other way to explain it.
Result I wanted is as below :
Explanation for this result is as below :







