-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: [non-expirenced] mapping 5 tables and 2 query parameters
PostPosted: Thu Jan 20, 2005 12:17 am 
Newbie

Joined: Fri Dec 17, 2004 12:17 pm
Posts: 5
I am converting aplication that use SQL queries to Hibernate.
Having problem with query that has 5 tables and two query parameters.

I have tables
Code:
-------
Users
id
-------
---------
Groups
id
---------
--------
Items
id
--------
---------------------
User_group
user_id | group_id
---------------------
---------------------
Items
id |  type
----------------------
--------------------------------------------
Item_access
item_id | user_id | group_id | access_level
---------------------------------------------

The task is: to select "Item"s that are linked to "User".
Link table is "item_access", and user may have non-direct access to item through "Group" membership in "user_group" table.

In old system there was query like this:
Code:
select item.id FROM users,groups,user_group, items, item_access WHERE
users.id=user_group.user_id, group.id=user_group.group_id,
(users.id=item_access.user_id OR group.id=item_access.group_id)
AND item_access.access_level=X , item.type=Y

Query also has two parameters for items, type of item and access evel of item.

With hibernate the way to do it is to map User class.
So in Java call should be
Code:
User.getItems(itemType,itemAccessLevel);


So far I add <set> to mapping, something like this:
Code:
<class name="Users">
....
<set name="items" table="items_access">
      <key column="user_id"/>
      <many-to-many column="item_id" class="Items" />
</set>
...

    How can I add Item_access link table and user_group link table to this mapping?
    How can I introduce parameters for Items table in query?
    I couldn't find any examples of mapping with more than 3 tables and query parameters. Is there any ?


Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.