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: Discriminators and one to many...
PostPosted: Thu Mar 20, 2008 6:24 am 
Newbie

Joined: Wed Mar 19, 2008 3:09 pm
Posts: 2
hi

i'm a newbie with hibernate 3, i have 2 tables in a mysql database, i have some java class and i need to mapp them to the database

i have 2 class who extend of my main class

class

abstract Role
List<Transiger> mTransiger;


User extends role
login
password
List<Id> mGroupId


Group extends role
List<Id> mUserIds


Id
lgVal
strVal

it' lgVal who will be generated for the primary key


database

t_role
------------
id_role (autoincrement)
login
password
typeRole(used to insert User or Group)

t_role_role
-----------------
idRoleRole (autoincrement)
idRoleFK1
idRoleFK2


t_role
id_Role / typeRole
-----------
1 user
2 user
3 group
4 group
5 user

t_role_role
iRoleRole / idRoleFK1 /idRoleFK2
--------------------
1 1 3
2 1 4
3 2
4 5 3

a user can have 0 or many group

t_role and t_role_role information

user 1 is a member of group 3 et 4
user 2 is not a member of any group
user 5 is a member of group 3

after readed hibernate document, i think i should use table per class hierarchy


it's my mapping file

Code:

    <hibernate-mapping>
       
        <class name="test.Role" table="t_role">
           
            <id name="id" type="long" column="idRole">
                <generator class="increment"/>
            </id>
           
            <discriminator column="typeRole" type="string"/>
           
            <subclass name="test.User" discriminator-value="User">
                <property name="login" column="login"/>
                <property name="password" column="password"/>             
            </subclass>
           
            <subclass name="test.Group" discriminator-value="Group"> 
               
            </subclass>
           
        </class>
       
    </hibernate-mapping>



i don't if i need to put in the subclass the one to many relation?
does i need to create another section in this file for t_role_role table?

help would be very appreciate...


thank


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.