-->
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: Bidirectional Association
PostPosted: Tue Sep 12, 2006 6:22 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
I'm trying to implement the following association in Hibernate:

I have Users which belong to an Organization via an association class called SecurityRole, which identifies the nature of that relationship (i.e. are they an ADMIN or merely a USER). As an aside, a user may also be a SYSADMIN, which is not associated with an Organization.

So a User has a one-to-many relationship with SecurityRole, as does the Organization. In other words, a User may fulfill multiple SecurityRoles in multiple Organizations. Likewise, an Organization will be associated with multiple Users. This association can be established either by editing the User or the Organization.

The problem I'm having is that I can successfully set up either the User or Organization side of the relationship, but not both at the same time. If I map it to successfully update the SecurityRole via the User, I cannot update it via the Organization. When I try, I get a StaleStateException.

Here are my mappings:

User:

Code:
   /**
    * @hibernate.set lazy="false" cascade="all-delete-orphan"
    *                table="security_role"
    *                inverse="true"
    *
    * @hibernate.collection-key column="user_key"
    *
    * @hibernate.collection-one-to-many class="SecurityRole"
    */
   public Set getSecurityRoles() {...


Organization:

Code:
   /**
    * @hibernate.set lazy="false"
    *       cascade="none"
    *      table="security_role"
    *      inverse="true"
    *
    * @hibernate.collection-key column="organization_key"
    *
    * @hibernate.collection-one-to-many class="SecurityRole"
    */
   public Set getSecurityRoles() {...


SecurityRole:

Code:
   /**
    * @hibernate.many-to-one class = "User"
    *                        column="user_key"
    */
   public User getUser() {...

   /**
    * @hibernate.many-to-one class =
    *                        "Organization"
    *                        column="organization_key" not-null="false"
    */
   public Organization getOrganization() {...

I'm sure this is a simple one. Any help would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 2:52 pm 
Newbie

Joined: Tue Oct 17, 2006 2:44 pm
Posts: 2
Location: Rio de Janeiro - Brazil
I'm having the same problem!!!

Sombary cul'd help us???

_________________
Leonardo Nunes
System Analyst


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.