Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Join Problems

 
Robert Wiscup
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
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
 
Prashant R Kataria
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