-->
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.  [ 8 posts ] 
Author Message
 Post subject: One column to multiple columns of different tables
PostPosted: Sat Jan 31, 2004 2:20 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
Hello:

I am not sure how to map this.

Table A { a(pk) , b ,c}

Table B {d, b (pk)}

Table C{f, b (pk)}


Please let me know if this insufficient information and i will be glad to give more information .


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2004 2:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I dont get what you want to do here. Please be more detailed what this should really represent.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2004 2:56 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
My question is how to map the property b of Table A to b of table B and to Table C.

So single property has to mapped to two columns on two different tables??? Pls advice.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2004 2:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You mean some entries in your b column of table A relate to entries of table B and some to table C? If yes, I don't think you can map this, this is a really broken relational model.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2004 8:34 pm 
Newbie

Joined: Sat Jan 31, 2004 8:22 pm
Posts: 4
This is similar to what I am trying to do. I am using tomcat realm based security and it requires you to have 2 tables each haveing the same userName.(I included userId also so that I can update the userName) I am trying to figure this out and can't find documention on how to do it, unless I didn't understant it.

fields...
userId
userName
password
role

These fields have to be stored in the tables user and userRole

user table has these column.
userId (pk)
userName
password

userRoles table has
userId (pk)
userName
role

I dont know how to map this to the database.
Thanks for any help


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2004 8:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well you should be able to map this one very easily as a parent-child relationships using one-to-many and many-to-one


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2004 9:07 pm 
Newbie

Joined: Sat Jan 31, 2004 8:22 pm
Posts: 4
I am pretty new. All I have done so far is a simple one class one table mapping.

So I would make 2 mapping files? One for each table in the database? then using one-to-many and many-to-one reference the other tables mapping?

This is a one to one relationship. So why whould I use a one-to-many and many-to-one? This is my mapping so far. Would you mind pointing out what I have to change?

Code:
<hibernate-mapping>
    <class name="com.jonathonbrozny.projmgmt.persistence.dto.SystemUserDTO" table="users">
      <id name="userId" type="integer" unsaved-value="0">
         <generator class="identity"/>
      </id>
        <property name="firstName"/>
        <property name="lastName"/>
        <property name="password"/>
        <property name="loginId"/>
        <property name="role"/>
    </class>

</hibernate-mapping>


The loginId and role have to go into the userRole table along with the generated Primary Key (userId).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 01, 2004 9:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well, if a user can have multiple roles its a one-to-many, otherwise a one-to-one. I suggest you read the according chapters of the docs, or some of the tutorials listed here http://www.hibernate.org/78.html#A3


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.