Hi Folks

I have a problem where I am getting the below error

NHibernate.PropertyValueException: not-null property references a null
or transient valueBlog.Core.Model.Entities.Account.User.

I have a User object which has an Account property, and have a uni
directional association between the objects. I have my mapping and
classes below and was wondering if someone could point me in the
direction of where I'm going wrong

classes-

public class User : BaseEntity
{

        public virtual string Forename { get; set; }

        public virtual string Surname { get; set; }


        public virtual Account Account { get; protected set; }

        public virtual void SetAccount(Account account)
        {
            this.Account = account;
        }

}


public class Account : BaseEntity
{
        public virtual string Username { get; set; }

        public virtual string Password { get; set; }

        public virtual UserSecurityLevel SecurityLevel { get; set; }

        public virtual User User { get; protected set; }

        public virtual void SetUser(User user)
        {
            this.User = user;
        }
}

mappings-

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-
import="true"
                   namespace="Blog.Core.Model.Entities"
assembly="Blog.Core" default-lazy="false">
        <class name="User" table="Users">

                <id name="Id" type="Int32">
                        <generator class="native" />
                </id>

                <version name="Version" type="Int32" unsaved-value="-1"/>
                <property name='Active' />

                <property name="Forename" type="String" column="Forename"/>

                <property name="Surname" type="String" column="Surname"/>

                <!-- Relationship with Account-->
                <join table="UsersAccounts" optional="true">
                        <key>
                                <column name="UserId" unique="true" />
                        </key>
                        <many-to-one name="Account" column="AccountId" 
not-null="true"
unique="true" cascade="all-delete-orphan" />
                </join>

        </class>
</hibernate-mapping>


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-
import="true"
                   namespace="Blog.Core.Model.Entities"
assembly="Blog.Core" default-lazy="false">
        <class name="Account" table="Accounts">

                <id name="Id" type="Int32">
                        <generator class="native" />
                </id>

                <version name="Version" type="Int32" unsaved-value="-1"/>
                <property name='Active' />

                <property name="Username" type="String" column="Username"/>

                <property name="Password" type="String" column="Password"/>

                <property name="SecurityLevel" column="SecurityLevel"/>

                <!-- Relationship with User -->
                <join table="UsersAccounts" inverse="true" optional="false">
                        <key>
                                <column name="AccountId" unique="true" />
                        </key>
                        <many-to-one name="User" column="UserId" not-null="true"
unique="true" />
                </join>

        </class>
</hibernate-mapping>

I have a table called Users, Accounts, and a link table called
UsersAccounts which stores the primary keys from the Users and
Accounts tables to associate the user and account. Any advice will be
appreciated

Thanks



-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to