aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate : many to many mapping and inner join query results. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate : many to many mapping and inner join query results." Watch "Hibernate : many to many mapping and inner join query results." New topic
Author

Hibernate : many to many mapping and inner join query results.

vani venkat
Ranch Hand

Joined: Nov 21, 2006
Posts: 142
hi,
I have 2 two tables(css_job and css_candidate) with many to many mapping. it is normalized and many to many mappings are put in table called css_candidatejob.

I have to show all the candidates and jobs provided that there is mapping between these two in css_candidatejob.
query is "select c.firstName ,j.title from css_job j inner join css_candidate c"

i am trying to achieve this using hibernate mappings and HQL.

here is my candidate mapping.


here is job mapping.


java beans(Job and Candidate) have private String attributes with the same name and sets with candidates and jobs as names.

here is the code that fires inner join between these two tables.


now my questions is how to show firstName from this result. for timebeing i am trying to print first name for tiem being but need fields from both job and candidate. so i can not specifically say select candidate in query and assign it to candidate Class.

Please suggest. it could be something very simple as i have started working with hibernate very recently.
thanks

SCJP 1.4, SCWCD 1.5
vani venkat
Ranch Hand

Joined: Nov 21, 2006
Posts: 142
sorry here is the query that is returning expected results. how should i map in hibernate.

select c.firstName,c.lastName,j.jobTitle,cj.status from css_candidate c,css_candidatejob cj,css_job j where c.candidateSeq = cj.candidateSeq and cj.jobSeq = j.jobSeq


should i have separate mapping file and java bean persistent class for css_candidatejob? and do "from candidateJob". this will return all records in candidateJob table as a list of candidateJob beans. Now how to load candidate and job classes for each of the rows to get firstName and jobTitle?

really appreciate help in this.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Hibernate : many to many mapping and inner join query results.