Question

I have tried to model the job portal use case as in class diagram below. I have made Skill entity as shareable by both job as well as job seeker hoping to reuse.

I have revised my oo design since I am sharing the skill I suppose it means its M:N relation instead of 1:N.

questions:

How can I do below things using hibernate ? do I need to resort to SQL ?

  1. since Skill has M:N relation it will need association table JobSkill and SeekerSkill. how to create job or seeker instance so that they use the existing skill in database ?
  2. I need to do skill matching such that job skill requirement is subset of candidate skills for:
    a) employer e1: find all candidates - 1{job + 1{candidate}N }N
    b) candidate c1: find all jobs - 1{job + employer }N

I am thinking to add a Business Service class for this case as JobPortal with some methods as below pseudo code. If one can answer the HQL query needed for the method findJobsForSeeker:

public class JobPortal {

  public int createEmployer(String name, Address address) {
    Employer e = null;
    HBUtil.create(e = new Employer(name, address));
    return e.getId();
  }

  public void addJobToEmployer(int empid, String jobName, String[][] skills) {
    Employee e = HBUtil.get(empid, Employee.class);
    Job j = new Job(jobName);
    Skill s = null;
    for(int i=0; i<skills.length; i++) {
      s = HBUtil.find(skills[i][0], skills[i][1], Skill.class);
      if (null == s) {
        s = new Skill(skills[0], Interger.parseInt(skills[1])); //name, experience
      }
      j.add(s);

    }
    e.add(j);
    HBUtil.save(e);
  }

  public int createSeeker(String name) {
    Seeker s = null;
    DBUtil.create(s = new Seeker(name));
    return s.getId();
  }

  public void addSkillsToSeeker(int sid, String[][] skills) {
    Seeker seeker = HBUtil.get(sid, Seeker.class);
    for(int i=0; i<skills.length; i++) {
      s = HBUtil.find(skills[i][0], skills[i][1], Skill.class);
      if (null == s) {
        s = new Skill(skills[0], Interger.parseInt(skills[1])); //name, experience
      }
      seeker.add(s);
    }
    HBUtil.save(seeker);
  }


  public void findJobsForSeeker(int sid) {
   //what HQL do use ? 
  }

}
Was it helpful?

Solution

To answer you first question: You search for the skills you want to attach to the new job or seeker (with a HQL query). Once you have found the skills, you add them to the collection of skills of the new job or seeker:

List<Skill> skills = session.createQuery("select skill from Skill skill where ...")
                            .list();
for (Skill skill : skills) {
    newJob.addSkill(skill);
}

I don't understand the syntax used in your second question. If you want to find all seekers who have all the skills in a given set of skills:

select seeker from Seeker seeker where not exists (
    select skill.id from Skill skill where skill in (:skillSet)
    and skill.id not in (select skill2.id from Seeker seeker2
                         inner join seeker2.skills skill2
                         where seeker2 = seeker))

OTHER TIPS

It is not totally clear what you are asking, but I'll try to add some more

1) If your questions is how to map the entities in hibernate, you can look up using ManyToMany and JoinTable annotations

(http://www.dzone.com/tutorials/java/hibernate/hibernate-example/hibernate-mapping-many-to-many-using-annotations-1.html).

You can also model ManyToMany relationships using 2 OneToMany if you create an actual SeekerSkill entity (e.g. one Seeker has many SeekerSkills, and one Skill has many SeekerSkills).

If your question is how to populate the jobs/seekers with existing skills in the database - then I would just write a one-time SQL script to populate my association tables with the appropriate skills (jobSkills and seekerSkills).

2) One way to check for subsets, assuming jobs/seekers don't list the same skill more than once, would to be to do a join on skills, group by the job/seeker and make sure that you get the appropriate count.

For example,
Seeker - jeff has skills: java, web development, design
Job - jobA requires skills: java, design

Jeff is looking for jobs that matches his skills

This is SQL, so you'd have to convert it HQL

select job_id from job_skill
  inner join seeker_skill on job_skill.skill = seeker_skill.skill
 where seeker_id = :seeker_id // this is a var for jeff's id
 group by job_id
having count(*) > :num_required_skills // in our case, 2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top