Dies ist die Staff-Klasse
Code: Select all
package com.oouweb.staffrequestapp.model.entity;
import com.oouweb.staffrequestapp.model.constant.StaffType;
import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Data
@NoArgsConstructor
@Entity
@Table(name = "staffs")
public class Staff {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(nullable = false, unique = true)
private String staffId;
@Column(nullable = false, length = 25)
private String firstName;
@Column(nullable = false)
private String lastName;
@Column(nullable = false, length = 25)
private String middleName;
@Column(nullable = false, unique = true)
private String email;
@Column(nullable = false)
private String encryptedPassword;
@Enumerated(EnumType.STRING)
private StaffType staffType;
@Column(nullable = true)
private String profilePicturePathId;
@Column(name = "is_valid")
private boolean isValid;
@Column(nullable = false, length = 14)
private String phoneNumber;
@Temporal(TemporalType.TIMESTAMP)
private Date dateCreated;
@ManyToOne(fetch = FetchType.EAGER)
private Department department;
@ManyToOne(fetch = FetchType.EAGER)
private NonAcademicUnit nonAcademicUnit;
@OneToMany(fetch = FetchType.LAZY)
private List staffRequests = new ArrayList();
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "admin_staff_responses",
joinColumns = @JoinColumn(name = "staff_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "request_id")
)
private List adminStaffResponses = new ArrayList();
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "staff_roles",
joinColumns = @JoinColumn(name = "staffId", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "roleId", referencedColumnName = "id")
)
Code: Select all
private List roles = new ArrayList();
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Staff staff = (Staff) o;
return id == staff.id;
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
}
Code: Select all
package com.oouweb.staffrequestapp.model.entity;
import com.oouweb.staffrequestapp.model.constant.RequestResponseStatus;
import com.oouweb.staffrequestapp.model.constant.RequestStatus;
import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Data
@NoArgsConstructor
@Entity
@Table(name = "staff_requests")
public class StaffRequest {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(nullable = false)
private String requestId;
@Column(nullable = false)
private String requestSubject;
@Column(length = 1000)
private String reasonForRequest;
private String attachmentUrl;
@Enumerated(EnumType.STRING)
private RequestStatus requestStatus;
@Enumerated(EnumType.STRING)
private RequestResponseStatus responseStatus;
@OneToMany(fetch = FetchType.EAGER)
@JoinTable(name = "admin_request_reviews ")
List reviews = new ArrayList();
@Temporal(TemporalType.DATE)
private Date requestDate;
@ManyToOne(fetch = FetchType.EAGER)
private Staff staff;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StaffRequest that = (StaffRequest) o;
return id == that.id;
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
}
`
I tried to use native query not but it was bringing ambiguous attribute
`@Query(value = """
SELECT id, request_id, request_subject, reason_for_request, attachment_url, request_status, response_status, request_date
FROM[tag:tag-name]
admin_staff_responses asr
JOIN
staff_requests sr
ON
asr.request_id = sr.id
WHERE
asr.staff_id = :staffId
""", nativeQuery = true)
List findByStaff(int staffId);`