java - How can I select with hibernate.query from an intermediate table -
i have 3 tables job
, jobseeker
, job_applications
intermediate table. relation between job
, jobseeker
n n. how can write hibernate query or criteria select list(job) job.id
, job.applicantscount
counts how many jobseeker
applied job.
job
entity:
@manytomany @jointable(name="job_applications", joincolumns={@joincolumn(name="id_job", referencedcolumnname="id")}, inversejoincolumns={@joincolumn(name="id_job_seeker", referencedcolumnname="id")}) private list<jobseeker> jobseekers = new arraylist<jobseeker>(); @transient @expose private integer applicantscount = 0; ...
jobseeker
entity:
@manytomany(fetch=fetchtype.lazy) @jointable(name="job_applications", joincolumns={@joincolumn(name="id_job_seeker", referencedcolumnname="id")}, inversejoincolumns={@joincolumn(name="id_job", referencedcolumnname="id")}) @fetch(fetchmode.subselect) private list<job> jobs = new arraylist<job>(); ....
in normal sql, write this: select id,(select count(*) job_applications id_job = id ) applicantscount job
this works need hibernate.query or hibernate.criteria in list(job). can me write query hibernate?
solution: manish comment resolved problem read it
its not clear. should write entities give better abstraction. why can't have list<jobapplications>
within job
class can list:
criteria crit = s.createcriteria(job.class); list<job> jobs =crit.getlist(); for(job j:jobs){ //j.getid returns id of job.....and... //j.getjobapplications.size() returns count particular job }
Comments
Post a Comment