aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Join Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Join Problems" Watch "Hibernate Join Problems" New topic
Author

Hibernate Join Problems

Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
Hi All,

I'm trying to do this SQL join in HQL in Hibernate . . .



basically a join on Defect and FunctionalArea Table. However, I'm still learning Hibernate and I don't understand how to do the configuration properly and the exact HQL syntax. Here's what I have now:

************ Defect.hbm.xml ********************



************ FunctionalArea.hbm.xml ********************




Can anyone tell me if I've done the associations and join syntax correctly?

Thanks,

Rob
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Well mapping is only half the part. You mapped your association. Now in HQL you have to say you want to fetch the association. So the FROM portion of your HQL would look like.

"From Defect d JOIN d.functionalareas"

Now make sure you follow Java standard on property names and using correct capitalization and camel casing. I would expect to see Defect has a property called functionalAreas, when the A, since it starts a new word is capitalized. And in the HQL the alias be a lower case d, not "D"

Hope that helps

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Prashant R Kataria
Greenhorn

Joined: Jul 23, 2007
Posts: 20
I doubt your mapping will not work.






Key column will map to a foreign key in funcionalarea table, I can see that both pk and fk of functional area share the same name with pk having id generator as native in functionalarea. This is wrong.

You should use different name for foreign key and then follow Mark.


-
Prashant Kataria
SCJP 5.0

"If you are going through hell, keep going!!!"
Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
Hi Mark, Prashant,

Thanks for your help . . .

Ok, now the two queries below seem to execute without error but I get no results . . .




so I'm missing something else apparently . . . working on this . . .



Oh, and here's a little more information:

In the end, I'm actually trying to execute the HQL equivalent of the following sql:



I would like the list that results from the HQL equivalent of the above SQL to be of type "DEFECT" so I can use the displaytag library to display it (here, I admit I'm assuming that it has to be a list of type DEFECT and not just an array of generic objects) . . . At any rate, that's where I want to get to eventually . . .

Rob

Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
Robert Wiscup wrote:Hi All,

I'm trying to do this SQL join in HQL in Hibernate . . .



basically a join on Defect and FunctionalArea Table. However, I'm still learning Hibernate and I don't understand how to do the configuration properly and the exact HQL syntax. Here's what I have now:

************ Defect.hbm.xml ********************



************ FunctionalArea.hbm.xml ********************




Can anyone tell me if I've done the associations and join syntax correctly?

Thanks,

Rob
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Join Problems