NHibernate staging table

Hey. I'm looking for some help in mapping the following tables to the hibernate mapping file: schema image http://barry-jones.com/temp/sch2.jpg

I am trying to populate a localCalandarGroups list with associated local CALendar groups when loading my userVOs. I am using an intermediate table (user_localCalendarGroup) to store the user ids and localCalendarGroup

 public class UserVO
{
    public virtual int id { get; set; }
    public virtual string name { get; set; }
    public virtual string pass { get; set; }
    public virtual string email { get; set; }
    public virtual string level { get; set; }
    public virtual List<LocalCalendarGroupVO> localCalendarGroups { get; set; }
}
public class LocalCalendarGroupVO
{

    public virtual int id { get; set; }
    public virtual string name { get; set; }

}

      

This is my mapping file so far. How can I make NHibernate staging table information?

 <class name="UserVO" table="tb_users" lazy="false">

<id name="id" column="id">

  <generator class="native" />

</id>

<property name="name" />
<property name="pass" />
<property name="level" />
<property name="email" />
<property name="localCalendarGroups"/>

      

Any help pointers is greatly appreciated.

0


source to share


2 answers


The first thing I would suggest you is to use IList instead of List to map the localCalendarGroups association in your domain classes. This will allow lazy loading of the collection. And here is the mapping file for the UserVO class:

<class name="UserVO" table="tb_users">
    <id name="id" column="id">
        <generator class="native" />
    </id>
    <property name="name" />
    <property name="pass" />
    <property name="level" />
    <property name="email" />

    <bag name="localCalendarGroups" table="user_localCalendarGroup">
        <key column="userID" />
        <many-to-many class="LocalCalendarGroupVO" column="calID" />
    </bag>
</class> 

      



And the corresponding class definition:

public class UserVO
{
    public virtual int id { get; set; }
    public virtual string name { get; set; }
    public virtual string pass { get; set; }
    public virtual string email { get; set; }
    public virtual string level { get; set; }
    public virtual IList<LocalCalendarGroupVO> localCalendarGroups { get; set; }
}

      

+4


source


0


source







All Articles