ooad - OO design and hibernate -
i have tried model job portal use case in class diagram below. have made skill entity shareable both job job seeker hoping reuse.
i have revised oo design since sharing skill suppose means m:n relation instead of 1:n.
- http://imagebin.org/219822 (revised m:n relation skill)
- http://imagebin.org/219680 (old 1:n relation skill)
questions:
how can below things using hibernate ? need resort sql ?
- since skill has m:n relation need association table jobskill , seekerskill. how create job or seeker instance use existing skill in database ?
- i need skill matching such job skill requirement subset of candidate skills for:
a) employer e1: find candidates - 1{job + 1{candidate}n }n
b) candidate c1: find jobs - 1{job + employer }n
i thinking add business service class case jobportal methods below pseudo code. if 1 can answer hql query needed 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 use ? } }
to answer first question: search skills want attach new job or seeker (with hql query). once have found skills, add them collection of skills of new job or seeker:
list<skill> skills = session.createquery("select skill skill skill ...") .list(); (skill skill : skills) { newjob.addskill(skill); }
i don't understand syntax used in second question. if want find seekers have skills in given set of skills:
select seeker seeker seeker not exists ( select skill.id skill skill skill in (:skillset) , skill.id not in (select skill2.id seeker seeker2 inner join seeker2.skills skill2 seeker2 = seeker))
Comments
Post a Comment