• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate query question

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using hibernate for the first time in a 'real' project. These are 3 of the tables:

Projects
---------
keyproj
projusers(set)
....


ProjUsers
----------
keyproj
keyuser
role


Users
-------
keyuser
username
projusers(set)
....


The relationships are set up correctly (I think), I'm just not sure how to construct the query. What I have to begin with is the users' username. How can I also load all of the projects that user is part of?

Thanks for the help.

[ November 03, 2004: Message edited by: Clifford Adams ]
[ November 03, 2004: Message edited by: Clifford Adams ]
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using hibernate for the first time in a 'real' project. These are 3 of the tables:

Projects
---------
keyproj
projusers(set)
....


ProjUsers
----------
keyproj
keyuser
role


Users
-------
keyuser
username
projusers(set)
....


The relationships are set up correctly (I think), I'm just not sure how to construct the query. What I have to begin with is the users' username. How can I also load all of the projects that user is part of?

Thanks for the help.

-- Should be pretty simple. If the relationships have been properly defined in your mapping files then all you have to do is run the query "from Users where username = :inUserName"

This will give you a list of users(hopefully just one) and since each user Object has a set of projusers object you should be able to iterate over that set. For each item , cast it to ProjUsers . Btw each ProjUser should have a project also,( I think) so you can get it off of that object, else get the keyproj field identifier property from the ProjUsers and load the Project based on that field.


HTH
 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed Sagar suggestion is correct. What is interesting is how have you mapped the real multi-to-multi relation? (this way you will find out what entities are directly accesible from your User: either ProjectUser or directly Project).

./pope
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic