Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Hibernate Join Problems  RSS feed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!