-->
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: Self-Referencing DB Entry
PostPosted: Tue Feb 07, 2006 6:51 am 
Newbie

Joined: Tue Feb 07, 2006 6:18 am
Posts: 1
Hi all,

i have several DB tables to represent a role-based-access-model.
One table contains the roles users may have, whereby a role may have a parent role. So the table looks like this:

role_id (PK) | role_name | parent_role_id

when role_id and parent_role_id equals, this should indicate that a role has no parent role (parent_role_id can't be null because it's an int in DB).

Hibernate will now reference parent-role to the role object itself (role == parentRole), when role_id and parent_role_id in DB equals.

How can i configure a mapping that doesn't set the parent-role (keeps it null) in the case described above?

Here is my existing mapping:
Code:
<class name="Role" table="ROLE" lazy="false">
        <id name="roleID" type="integer">
            <column name="ROLE_ID" precision="22" scale="0" />
            <generator class="assigned" />
        </id>
        <many-to-one name="parentRole" class="Role" fetch="select"
            lazy="false">
            <column name="PARENT_ROLE_ID" precision="22" scale="0" not-null="true" />
        </many-to-one>
...
</class>




thanks for advice


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
can't see how you can do it without "hurting" save/updates.

what about you map the property to the field (or some other internal get/sets) and then let your get/set methods handle the logic ?

_________________
Max
Don't forget to rate


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.