Когда я внедрял соединение Criteria API для своего весеннего начального обучения, я попытался объединить 2 класса и получить результат. Но когда я внедряю и работаю, я получаю следующую ошибку:
Unable to locate appropriate constructor on class [com.spacestudy.model.Investigator]. Expected arguments are: com.spacestudy.model.Employee
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.spacestudy.model.Investigator]
И мой класс Employee. java, как показано ниже,
@Entity
@Table(name="employee")
public class Employee implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "employee_seq_generator")
@SequenceGenerator(name = "employee_seq_generator", sequenceName = "employee_seq",allocationSize=1)
@Column(name="nemp_id",columnDefinition="serial")
public Integer nEmpId;
@Column(name="semp_name")
public String sEmpName;
@Column(name="sdesignation")
public String sDesignation;
@Column(name="ninst_id")
public Integer nInstId;
@Column(name="ndept_id")
public Integer nDeptId;
@Column(name="sclient_emp_id")
public String sClientEmpId;
@Column(name="ntemp_emp_id")
public Integer nTempEmpId;
@Column(name="bis_paid")
public boolean bIsPaid=true;
@Column(name="sunpaid_comment")
public String sUnpaidComment;
@ManyToOne(optional=true)
@JoinColumn(name="ndept_id", insertable = false, updatable = false)
public Department department;
@OneToMany(cascade = CascadeType.ALL,mappedBy="nEmpId")
public Set<Investigator> employeeInvestigatorJoinMapping;
public Employee() {
}
public Employee(Integer nEmpId, String sEmpName, String sDesignation, Integer nInstId, Integer nDeptId,
String sClientEmpId, Integer nTempEmpId, boolean bIsPaid, String sUnpaidComment, Department department,
Set<Investigator> employeeInvestigatorJoinMapping) {
super();
this.nEmpId = nEmpId;
this.sEmpName = sEmpName;
this.sDesignation = sDesignation;
this.nInstId = nInstId;
this.nDeptId = nDeptId;
this.sClientEmpId = sClientEmpId;
this.nTempEmpId = nTempEmpId;
this.bIsPaid = bIsPaid;
this.sUnpaidComment = sUnpaidComment;
this.department = department;
this.employeeInvestigatorJoinMapping = employeeInvestigatorJoinMapping;
}
}
И мой исследователь второго класса. java,
@Entity
@Table(name = "investigator")
@JsonInclude(JsonInclude.Include.NON_NULL) // avoiding null values
public class Investigator implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "investigator_seq_generator")
@SequenceGenerator(name = "investigator_seq_generator", sequenceName = "investigator_seq")
@Column(name="ninvestigator_id")
public Integer nInvestigatorId;
@Column(name="sinvestigator_name")
public String sInvestigatorName;
@Column(name="ninst_id")
public Integer nInstId;
@Column(name="stitle")
public String sTitle;
@Column(name="ntemp_investigator_id")
public Integer nTempInvestigatorId;
@ManyToOne(optional = false)
@JoinColumn(name="nemp_id",referencedColumnName="nemp_id")
public Employee nEmpId;
// Default Constructor.
public Investigator()
{
}
public Investigator(Integer nInvestigatorId, String sInvestigatorName, Integer nInstId, String sTitle,
Integer nTempInvestigatorId, Employee nEmpId) {
super();
this.nInvestigatorId = nInvestigatorId;
this.sInvestigatorName = sInvestigatorName;
this.nInstId = nInstId;
this.sTitle = sTitle;
this.nTempInvestigatorId = nTempInvestigatorId;
this.nEmpId = nEmpId;
}
}
И реализовал Criteria API, объединяясь следующим образом:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Investigator> cq = cb.createQuery(Investigator.class);
Root<Employee> rootInvestigator = cq.from(Employee.class);
Join<Employee ,Investigator> resultEmployeeMappingObj
= rootInvestigator.join("employeeInvestigatorJoinMapping");
cq.multiselect(rootInvestigator);
cq.where(cb.equal(resultEmployeeMappingObj.get("nEmpId"), 21638));
List<Investigator> results = em.createQuery(cq).getResultList();
return results;
Где я go ошибся?