• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Hibernate Join Problems

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Robert Wiscup
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Do not threaten THIS beaver! Not even with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic