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: Foreign Key Mapping Question
PostPosted: Tue Sep 21, 2004 3:57 pm 
Newbie

Joined: Tue Sep 21, 2004 3:39 pm
Posts: 1
Location: North Carolina
Hello All,

I'm very new to Hibernate and have tried various mappings to get a User object containing its role (already in User table) and the user's set of functions (role_function.fk_function) given the table definitions below. Both User and Fcn contain a foreign key into the Role table. How would the mappings look for these tables to get the function values loaded into the User object as a Collection of Integers?

Is the User/Role relationship considered many-to-one?
Is the Role/Fcn relationship considered one-to-many?
Is the User/Fcn relationship considered many-to-many?
Is there a way to make this happen in a single operation or does it have to be split into two steps?

Thanks, Gary


Is this on the right track?

<class name="User" table="USER">
<id name="pkUser" type="integer" column="PK_USER">
...
</id>
<property
column="FK_ROLE"
length="9"
name="fkRole"
not-null="true"
type="integer"
/>

<array name="fcns" table="USER">
<key column="FK_ROLE"/> <--User table FK column to use
<index column="I"/>
<many-to-many column="FK_ROLE" class="Fcn"/> <--Fcn table FK column to use
</array>
</class>


CREATE TABLE user (
pk_user number(9) not null primary key,
...
...
...
fk_role number(9) not null,
);

CREATE TABLE role (
pk_role number(9) not null primary key,
...
);

CREATE TABLE role_function (
pk_role_function number(9) not null primary key,
fk_role number(9) not null,
fk_function number(9) not null
);

[/b]


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.