Using EclipseLink-JPA2 I'm trying to create a dynamic query. Sample code below:
TypedQuery query = getEntityManager().createQuery("UPDATE Employee e SET e.employeeStatus.code = :statusCode WHERE e.employeeId = :employeeId", Employee.class);
EmployeeBean below:
@Entity
@Table(name = "employee", uniqueConstraints = {
@UniqueConstraint(columnNames = {"employee_id"})})
@XmlRootElement
public class Employee implements Serializable {
@Id
@Basic(optional = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "employee_id", nullable = false)
private Integer employeeId;
@JoinColumn(name = "employee_status", referencedColumnName = "code", nullable = false)
@ManyToOne(optional = false)
private EmployeeStatus employeeStatus;
//Other fields here
public EmployeeStatus getEmployeeStatus() {
return employeeStatus;
}
public void setEmployeeStatus(EmployeeStatus employeeStatus) {
this.employeeStatus = employeeStatus;
}
//Other getters-setters here
}
EmployeeStatus Bean below:
@Entity
@Table(name = "employee_status")
@XmlRootElement
public class EmployeeStatus implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "code", nullable = false)
private Integer code;
@Column(name = "descr", length = 32)
private String descr;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "employeeStatus")
private List<Employee> employeeList;
//Other fields here
@XmlTransient
public List<Employee> getEmployeeList() {
return employeeList;
}
public void setEmployeeList(List<Employee> employeeList) {
this.employeeList = employeeList;
}
//Other getters-setters here
}
During runtime I get the following error during the execution of the above line:
Error compiling the query invalid navigation expression [e.employeeStatus], cannot navigate association field [employeeStatus] in the SET clause target.
Why is this happening? If I try to update a simple column(String,int..) not object type is executed normally. Do I have to set any property inside my entity bean?