-->
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: Problem with many-to-many bag
PostPosted: Fri Jan 21, 2011 2:48 pm 
Newbie

Joined: Fri Dec 08, 2006 6:26 pm
Posts: 5
Hi,
No matter what I do, a bag contained on class FrontEndUser containing SecurableUserLevel instances it's not saved. Here all the details

Code:
    public class FrontEndUser : DBEntity<int>
    {
        public virtual string Name { get; set; }
        public virtual string LastName { get; set; }
        public virtual string DisplayName { get; set; }
        public virtual string Email { get; set; }
        public virtual DateTime DateOfBirth { get; set; }
        public virtual string Address { get; set; }
        public virtual string City { get; set; }
        public virtual string State { get; set; }
        public virtual string ZipCode { get; set; }
        public virtual DateTime CreationDate { get; set; }
        public virtual bool Active { get; set; }
        public virtual IList<SecurableUserLevel> UserLevels { get; set; }
        public virtual IList<SubscriptionProduct> Subscriptions { get; set; }
        public virtual IList<FrontEndUserLogin> Logins { get; set; }   
     
    }


and

Code:
public class SecurableUserLevel : DBEntity<int>
    {
        public static readonly int LEVEL_NOT_LOGGED = 1;
        public static readonly int LEVEL_BASIC = 2;

        public virtual string Name { get; set; }
    }
}


and the mappings

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="AdminNewsCms.BusinessObjects" namespace="AdminNewsCms.BusinessObjects.Security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:nhibernate-mapping-2.2 ..\nhibernate-mapping.xsd">
  <class name="FrontEndUser" table="FrontEndUsers">
    <id name="Identity" column="FrontEndUserId">
      <generator class="identity"/>
    </id>
    <property name="Name"/>
    <property name="LastName"/>
    <property name="DisplayName"/>
    <property name="Email"/>
    <property name="DateOfBirth"/>
    <property name="Address"/>
    <property name="City"/>
    <property name="State"/>
    <property name="ZipCode"/>
    <property name="CreationDate"/>
    <property name="Active"/>

    <bag name="UserLevels" table="FrontEndUsers_Securable_UserLevels" fetch="join">
      <key column="FrontEndUserId"/>
      <many-to-many column="SecurableUserLevelId" class="SecurableUserLevel" />
    </bag>

    <bag name="Subscriptions" table="FrontEndUserSubscriptions" inverse="true" cascade="all-delete-orphan">
      <key column="FrontEndUserId"/>
      <many-to-many column="SubscriptionProductId" class="SubscriptionProduct"/>
    </bag>

    <bag name="Logins" table="FrontEndUserLogins" inverse="true" cascade="all-delete-orphan">
      <key column="FrontEndUserId"/>
      <one-to-many class="FrontEndUserLogin"/>
    </bag>

  </class>
</hibernate-mapping>


and

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="AdminNewsCms.BusinessObjects" namespace="AdminNewsCms.BusinessObjects.Security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:nhibernate-mapping-2.2 ..\nhibernate-mapping.xsd">
  <class name="SecurableUserLevel" table="Securable_UserLevels">
    <id name="Identity" column="SecurableUserLevelId">
      <generator class="assigned"/>
    </id>
    <property name="Name" column="Name"/>
   </class>
</hibernate-mapping>


My code. The IList "UserLevels" is not been saved and that's driving me crazy.
Code:
            FrontEndUser frontEndUser = new FrontEndUser();
            frontEndUser.LastName = lastName;
            frontEndUser.Name = firstName;
            frontEndUser.DisplayName = displayName;
            frontEndUser.Email = email;
            frontEndUser.DateOfBirth = dateOfBirth;
            frontEndUser.Address = address;
            //ETC ETC ETC... next lines are the important ones
            frontEndUser.UserLevels = new List<SecurableUserLevel>();
            SecurableUserLevel userLevel = SecurableUserLevelService.GetSecurableUserLevel(SecurableUserLevel.LEVEL_NOT_LOGGED);
            frontEndUser.UserLevels.Add(userLevel);

            FrontEndUserService.Save(frontEndUser);


Thanks in advance


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.