#StackBounty: #java #spring-boot Criteria API Unable to locate appropriate constructor on class

Bounty: 50

When I am implementing the Criteria API join for my spring boot study, I tried joining 2 classes and fetching the result. But when I am implementing and running I am getting the following error,

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]

And my Employee.java class like the following,

public class Employee implements Serializable
private static final long serialVersionUID = 1L;

@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "employee_seq_generator")
@SequenceGenerator(name = "employee_seq_generator", sequenceName = "employee_seq",allocationSize=1)
public Integer nEmpId;

public String sEmpName;

public String sDesignation;

public Integer nInstId;

public Integer nDeptId;

public String sClientEmpId;

public Integer nTempEmpId;

public boolean bIsPaid=true;

public String sUnpaidComment;

@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) {
    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;

And my second class Investigator.java,

@Table(name = "investigator")
@JsonInclude(JsonInclude.Include.NON_NULL) // avoiding null values
public class Investigator implements Serializable 
private static final long serialVersionUID = 1L;

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "investigator_seq_generator")
@SequenceGenerator(name = "investigator_seq_generator", sequenceName = "investigator_seq")

public Integer nInvestigatorId;

public String sInvestigatorName;

public Integer nInstId;

public String sTitle;

public Integer nTempInvestigatorId;

@ManyToOne(optional = false)
public Employee nEmpId;

// Default Constructor.
public Investigator()
public Investigator(Integer nInvestigatorId, String sInvestigatorName, Integer nInstId, String sTitle,
        Integer nTempInvestigatorId, Employee nEmpId) {
    this.nInvestigatorId = nInvestigatorId;
    this.sInvestigatorName = sInvestigatorName;
    this.nInstId = nInstId;
    this.sTitle = sTitle;
    this.nTempInvestigatorId = nTempInvestigatorId;
    this.nEmpId = nEmpId;

And Implemented the Criteria API joining like the foolwoing,

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.where(cb.equal(resultEmployeeMappingObj.get("nEmpId"), 21638));
List<Investigator> results = em.createQuery(cq).getResultList();
return results;

Can anyone help me to find where I went in wring direction please?

Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.