-->
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.  [ 2 posts ] 
Author Message
 Post subject: please, help m with mapping for this relational structure!
PostPosted: Mon Mar 28, 2005 9:25 am 
Newbie

Joined: Tue Jan 11, 2005 9:51 am
Posts: 10
we have USERS table:

Code:
...
       USER_ID        bigint,
       USER_NAME    text,
...


and SKILLS table:

Code:
...
       SKILL_ID                  bigint,
       SKILL_NAME              text,
...


and we have "mediator" table, between USERS and SKILLS tables -- USERS_SKILLS:

Code:
...
       US_SKILL_ID                  bigint,
       US_USER_ID         bigint,
       US_SKILL_YEARS             bigint,
...



in practice it looks the following way.
there can be many USERS's, each of them has name and id.
also, there are a lot of SKILLS's, each of them as name and id.

each user can set for specified skills how many years he is experienced with it. (record in USERS_SKILLS)
if there is no such record - user has no experience with such skill.

how can we map this correctly?
can you help me with code example's of such mapping?

it would be perfect, if after mapping we will be able to see all SKILLS the following way (i.e. for user with id 1):


getUser(1).getSkills()

and we will have a list of ALL skills (from SKILLS table) and each of them will have information on how many years user is expereinced:

...
(in iteration)

Skill s;
...
s.getYears()
..





Thanks for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 29, 2005 7:37 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
The association between User and Skill is many-to-many, but you need to save additional info into the linking table (US_SKILL_YEARS in the USERS_SKILLS). So you cannot use many-to-many association in your mapping. You need additional linking entity class eg UserSkill. Please read the following "Best Practice": Don't use exotic association mappings on the http://www.hibernate.org/hib_docs/reference/en/html/best-practices.html

You asked for an example of the mapping, you could look into the following junit test
http://opensource.atlassian.com/project ... st-src.zip

There is a many-to-many association between MoslemMan and Woman through the Harem linking class. You can use your User instead of my MoslemMan, your Skill instead of my Woman and UserSkill instead of Harem. Everything should work fine.

_________________
Leonid Shlyapnikov


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

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.