Hi folks,
I have a User class and a Group class.
a User can be in many groups and a group can have many users.
Got a User, Group and UserGroup table.
Below is the mapping files for both user and group class. The thing is that it will save correctly. but when trying to use User.Groups.Count, it always return 0.
Any idea?
User.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Com.Progmatik.Filemanager.User, Com.Progmatik.Filemanager.DomainModel" table="Users">
<id name="IdUser" unsaved-value="0" access="nosetter.camelcase-underscore">
<generator class="native" />
</id>
<property name="Email" />
<property name="Username" />
<property name="Password" column="Psswrd" />
<bag name="Groups"
table="GroupUsers"
lazy="true"
cascade="save-update">
<key column="IdUser"/>
<many-to-many class="Com.Progmatik.Filemanager.User, Com.Progmatik.Filemanager.DomainModel" column="IdGroup" />
</bag>
</class>
</hibernate-mapping>
Group.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Com.Progmatik.Filemanager.Group, Com.Progmatik.Filemanager.DomainModel" table="Groups">
<id name="IdGroup" unsaved-value="0" access="nosetter.camelcase-underscore">
<generator class="native" />
</id>
<property name="Name" />
<property name="Description" />
<bag name="Users"
table="GroupUsers"
inverse="true"
lazy="true"
cascade="save-update">
<key column="IdGroup"/>
<many-to-many class="Com.Progmatik.Filemanager.Group, Com.Progmatik.Filemanager.DomainModel" column="IdUser" />
</bag>
</class>
</hibernate-mapping>
Thanks
|