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: Creating a 'parent'object from multiple mapping files\tables
PostPosted: Mon Mar 08, 2010 1:04 pm 
Newbie

Joined: Mon Mar 08, 2010 1:02 pm
Posts: 1
Hi Folks

I am trying to create an nHibernate mapping for a class structure like so:

Code:
class UserDetails{
   Guid id;
   User user;
   Role role;
   
   public User UserInfo{
      get;set;
   }
   
   public Role UserRoles{
      get;set;
   }
   
   public Guid ID{
      Get; set;
   }
}

class User{
   string name;
   int id;
   
   public string Name{
      get;set;
   }
   
   public int ID{
      get;set;
   }
}

class Role{

   string roleName;
   string roleDesc;
   int roleId;
   
   public string RoleName{
      get;set;
      }
      
   public string RoleDesc{
      get;set;
   }
      
   public int RoleID{
      get;set;
   }
}


The underlying DB structure is similar to the tables, but there is a linking table which links user and role using their respective IDs:
UserRoleLinkTable[
identity User_Role_ID (pk)
userID (FK to User table)
roleid (FK to Role table)
]

After playing about with nHibernate this is similar to what I want to try and achieve (but it doesnt work!):

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
  xmlns="urn:nhibernate-mapping-2.2"
  assembly="Admin"
  namespace="Admin"
>
  <class name="UserDetails" lazy="false" table="USER">
    <id name="ID">
      <generator class="guid"></generator>
    </id>

    <one-to-one name="UserInfo" class="User" lazy="false" cascade="none"/>

    <bag
      name="UserRoles"
      inverse="false"
      table="Role"
      lazy="false"
      cascade="none"
    >
      <key column="Role" />
      <many-to-many class="Role" column="ROLE_ID" />
    </bag> 
  </class>
</hibernate-mapping>


I have mappings\entities which appear to work for Role and User (used in other aspects of the project) objects but how do I pull this information into one UserDetails class? The point of the user details to be able to return all this information together as one object. Is it possible to create (for want of a better description) a container using an nHibernate mapping and map the data that way?

Hopefully there is enough info to help work this out - thanks in advance for all help given!

Cheers,

Morris


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.