HI ,
Im using the follwoing class Job.java @Entity @Table(name="WEB_UI_JOB") public class Job implements Serializable { @Id @Column(name="JOB_ALIAS") private String jobAlias; @ManyToOne @JoinColumn(name="SERVER_ALIAS") private Server serverAlias; @OneToMany(mappedBy="jobAlias") private Set<JobFunction> webUiJobFunctionCollection;
and this is JobFunction.java
@ManyToOne @JoinColumn(name="FUNCTION_ID" ,insertable=false, updatable=false) private Function functionId;
@ManyToOne @JoinColumn(name="JOB_ALIAS",insertable=false, updatable=false) private Job jobAlias;
Im using the following query to search Job.class public List<Job> search(String jobAlias, String serverAlias,String jobTitle){ Server server = null; if (serverAlias != null) { server = serverService.findById(serverAlias); }
Session session = PersistenceSessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Job.class); if (jobAlias != null) { criteria.add(Restrictions.eq("jobAlias",jobAlias)); } if (jobTitle != null) { criteria.add(Restrictions.eq("jobTitle",jobTitle)); } if (serverAlias != null) { criteria.add(Restrictions.eq("serverAlias",server)); } List<Job> jobList = criteria.list(); return jobList; }
the above query is working fine.Which is used to return the list based on the input to the search.Now i need to refine the list returned by search based on the funcitonId in the JobFunction table also. I need the search be modified with the new parameter added public List<Job> search(String jobAlias, String serverAlias,String jobTitle,string functionID){ Server server = null; if (serverAlias != null) { server = serverService.findById(serverAlias); } Session session = PersistenceSessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Job.class); if (jobAlias != null) { criteria.add(Restrictions.eq("jobAlias",jobAlias)); } if (jobTitle != null) { criteria.add(Restrictions.eq("jobTitle",jobTitle)); } if (serverAlias != null) { criteria.add(Restrictions.eq("serverAlias",server)); } List<Job> jobList = criteria.list(); return jobList; }
where functionID is searched based on JobAlias from job.java .
In the search function the parameter passed JobAlias may be null..but still the query should work retruning the list from Job.java
kindly help..thanks in advance
|