Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate query question

 
Clifford Adams
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • 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 ]
 
Sagar Bilgi
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic