In table I am saving integer values for applied, selected, not selected etc... What I thought is to use Enum in Java Domain class. I tried implementing it. While I am calling this domain from DAO, I am getting some weired error. Please find the code(s) below.
import java.util.Date;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import javax.persistence.*;
import static javax.persistence.GenerationType.IDENTITY;
@Entity
@Table(name="xxxxxx")
public class JobApplied{
public enum RSVP {
APPLIED_REJECTED(0),
APPLIED_SHORTLISTED(1),
SHORTLISTED_SELECTED (3),
SHORTLISTED_IN_PROGRESS (4),
SHORTLISTED_ON_HOLD (5),
SHORTLISTED_REJECTED (6);
private int value;
RSVP(int value) { this.value = value; }
public int getValue() { return value; }
public static RSVP parse(int id) {
RSVP rsvp = null;
for (RSVP item : RSVP.values()) {
if (item.getValue()==id) {
rsvp = item;
break;
}
}
return rsvp;
}
};
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id",unique = true, nullable = false)
private long id;
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name="job_opportunity_id")
@NotFound(action= NotFoundAction.IGNORE)
private JobOpportunity jobOpportunity;
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name="user_id")
@NotFound(action= NotFoundAction.IGNORE)
private Users users;
@Column(name="status")
private int RSVP_Status;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public JobOpportunity getJobOpportunity()
{
return jobOpportunity;
}
public void setJobOpportunity(JobOpportunity jobOpportunity)
{
this.jobOpportunity=jobOpportunity;
}
public Users getUsers()
{
return users;
}
public void setUsers(Users users){
this.users=users;
}
public RSVP getRSVP_Status () {
return RSVP.parse(this.RSVP_Status);
}
public void setRSVP_Status(RSVP rsvp) {
this.RSVP_Status = rsvp.getValue();
}
public void setRSVP_Status(int rSVP_Status) {
RSVP_Status = RSVP.parse(rSVP_Status).getValue();
}
}
While calling the above domain class using this method,
public List<JobApplied> getAppliedCandidates(long jobId) {
Map<String, Object> conditions = getConditionsTemplate();
conditions.put("status", (Integer)JobApplied.RSVP.APPLIED_SHORTLISTED.getValue());
//Error is not because of the above line.
conditions.put("jobOpportunity.jobOpportunityId", jobId);
return findByCriteria(null, conditions); //stack trace points the error in this line.
}
I am getting this error,
org.hibernate.QueryException: could not resolve property: status of: com.xxxx.xxxxx.domain.JobApplied
Kindly clear me where I am wrong. Hope my question is clear. Thank you in Advance.