When I update xml schmas in budget.hbm.xml as your suggestion 

> *    <many-to-one name="oAirport" column="AirportID"*
> *      class="Tec.Core.Model.Airport, Tec.Core" not-null="true" 
> cascade="save-update"/>*
> *    <many-to-one name="oInvestmentCode" column="InvestmentCodeID"*
> *      class="Tec.Core.Model.InvestmentCode, Tec.Core" not-null="true" 
> cascade="save-update"/>*
> *    <many-to-one name="oInvestmentType" column="InvestmentTypeID"**      
> class="Tec.Core.Model.InvestmentType, Tec.Core" not-null="true" 
> cascade="save-update"/>  *

    

I got the following exception class InvestmentCode.cs
------------------------------------------------------------------------------------------------------------------------

*public void AddBudget(Budget imntBudget){*
*            if (imntBudget != null && 
!_lInvestmentCodeBudgets.Contains(imntBudget)){*
*                imntBudget.oInvestmentCode = this;*

*                _lInvestmentCodeBudgets.Add(imntBudget); 
 // System.NotSupportedException : Collection is read-only*
*            }*
*        }*

I do not know what going on here again.

Any suggestion?

Best regards,

Veasna



On Monday, February 24, 2014 10:57:38 PM UTC+7, Ricardo Peres wrote:
>
> Try this:
>
> <many-to-one name="oInvestmentType" column="InvestmentTypeID"
>       class="Tec.Core.Model.InvestmentType, Tec.Core" not-null="true" 
> cascade="save-update" 
> />  
>
> On Monday, February 24, 2014 11:33:12 AM UTC, Veasna MUCH wrote:
>>
>>
>> Good afternoon,
>>
>> I have following database schemas
>>
>>
>> <https://lh4.googleusercontent.com/-TnjRxHcktjM/UwscRDvMOGI/AAAAAAAABx4/_6XhBJFgic4/s1600/ER+Diagram.JPG>
>> Here is my mapping file 
>>
>> *Airport*
>> -----------------------------------------------------------
>>
>> <?xml version="1.0" encoding="utf-8" ?>
>>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
>>>   <class name="Tec.Core.Model.Airport, Tec.Core" table="tblAirport" 
>>> lazy="false">
>>>     <id name="ID" column="AirportID" unsaved-value="0">
>>>       <generator class="identity" />
>>>     </id>
>>>     <property name="AirportCode" column="AirportCode" />
>>>     <property name="AirportFullName" column="AirportFullName" />
>>>    
>>>     <bag name="Budgets" table="tblBudget" inverse="true" 
>>> cascade="save-update">
>>>       <key column="AirportID" />
>>>       <one-to-many class="Tec.Core.Model.Budget, Tec.Core" />
>>>     </bag>
>>>     
>>>   </class>
>>> </hibernate-mapping>
>>
>>
>>
>>    * public class Airport:Entity<int> *
>> *    {*
>> *        private string _airportCode="";*
>> *        private string _airportFullName="";*
>> *        private IList<Budget> _airportBudgets = new List<Budget>();*
>>
>> *        private Airport() { }*
>> *        public Airport(string AirportCode, string AirportFullName) {*
>> *            this._airportCode = AirportCode;*
>> *            this._airportFullName = AirportFullName; *
>> *        }*                
>> *         public  string AirportCode**  {*
>> *            get { return _airportCode; }*
>> *            set { _airportCode = value; }*
>> *        }*
>> *        public  string AirportFullName** {*
>> *            get { return _airportFullName; }*
>> *            set { _airportFullName = value; }*
>> *        }*
>> *        public IList<Budget> Budgets** {*
>> *            get { return new List<Budget>(_airportBudgets).AsReadOnly(); 
>> }*
>> *            protected set { _airportBudgets = value; }*
>> *        }*
>> *        public void AddBudget(Budget air_budget)**{*
>> *            if (air_budget != null && 
>> !_airportBudgets.Contains(air_budget)){*
>> *                air_budget.oAirport = this; *
>> *                _airportBudgets.Add(air_budget);*
>> *            }*
>> *        }*
>>
>> *        public override int GetHashCode(){*
>> *            return (GetType().FullName + "|" + 
>> _airportCode.GetHashCode()).GetHashCode();*
>> *        }*
>>
>> *    }*
>>
>>
>>
>>
>> InvestmentCode
>> --------------------------------------------------------------
>>
>> <?xml version="1.0" encoding="utf-8" ?>
>>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
>>>   <class name="Tec.Core.Model.InvestmentCode, Tec.Core" 
>>> table="tblInvestmentCode" lazy="false">
>>>     <id name="ID" column="InvestmentCodeID" unsaved-value="0">
>>>       <generator class="identity" />
>>>     </id>
>>>     <property name="InvCode" column="InvestmentCode" />
>>>     <property name="InvCodeNote" column="InvestmentCodeNote" />
>>>   
>>>     <bag name="Budgets" table="tblBudget" inverse="true" 
>>> cascade="save-update">
>>>       <key column="InvestmentCodeID" />
>>>       <one-to-many class="Tec.Core.Model.Budget, Tec.Core" />
>>>     </bag>
>>>     
>>>   </class>
>>> </hibernate-mapping>
>>
>>
>>
>>  *  public class InvestmentCode: Entity<int> *
>> *    {*
>>
>> *        private string _investmentCode="";*
>> *        private string _investmentCodeNote="";*
>> *        private IList<Budget> _lstinvestmentCodeBudgets = new 
>> List<Budget>();*
>>
>> *        private InvestmentCode() { }*
>> *        public InvestmentCode(string investmentCode, string 
>> InvestmentCodeNote) {*
>> *            this._investmentCode = investmentCode;*
>> *            this._investmentCodeNote = InvestmentCodeNote ; *
>> *        }      *
>> *        public string InvCode {*
>> *            get { return _investmentCode ; }*
>> *            set { _investmentCode  = value; }*
>> *        }*
>> *        public string InvCodeNote {*
>> *            get { return _investmentCodeNote ; }*
>> *            set { _investmentCodeNote  = value; }*
>> *        }*
>> *        public IList<Budget> Budgets {*
>> *            get { return new 
>> List<Budget>(_lstinvestmentCodeBudgets).AsReadOnly(); }*
>> *            protected set { _lstinvestmentCodeBudgets = value; }*
>> *        }*
>> *        public void AddBudget(Budget investment_code_budget) {*
>> *            if (investment_code_budget != null && 
>> !_lstinvestmentCodeBudgets.Contains(investment_code_budget)){*
>> *                investment_code_budget.oInvestmentCode = this; *
>> *                _lstinvestmentCodeBudgets.Add(investment_code_budget);*
>> *            }*
>> *        }        *
>> *        public override int GetHashCode(){*
>> *            return (GetType().FullName +"|"+ 
>> _investmentCode.GetHashCode()).GetHashCode();*
>> *        }*
>> *    }*
>>
>>
>> InvestmentType
>>
>> -------------------------------------------------------------------------------
>>
>> <?xml version="1.0" encoding="utf-8" ?>
>>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
>>>   <class name="Tec.Core.Model.InvestmentType, Tec.Core" 
>>> table="tblInvestmentType" lazy="false">
>>>     <id name="ID" column="InvestmentTypeID" unsaved-value="0">
>>>       <generator class="identity" />
>>>     </id>
>>>     <property name="InvestmentTypeNote" column="InvestmentTypeNote" />   
>>>  
>>>     
>>>     <bag name="Budgets" table="tblBudget" inverse="true" 
>>>  cascade="save-update">
>>>       <key column="InvestmentTypeID" />
>>>       <one-to-many class="Tec.Core.Model.Budget, Tec.Core" />
>>>     </bag>
>>>     
>>>   </class>
>>> </hibernate-mapping>
>>
>>
>>
>> * public class InvestmentType: Entity<int> **{*
>>        
>> *        private string _investmentTypeNote="";*
>> *        private IList<Budget> _lstInvestmentTypeBudgets = new 
>> List<Budget>();*
>>
>> *        private InvestmentType() { }*
>>
>> *        public InvestmentType(string InvestmentTypeNote){            *
>> *            this._investmentTypeNote = InvestmentTypeNote ; *
>> *        }*
>> *        public string InvestmentTypeNote {*
>> *            get { return _investmentTypeNote ; }*
>> *            set { _investmentTypeNote  = value; }*
>> *        }*
>> *        public IList<Budget> Budgets {*
>> *            get { return new 
>> List<Budget>(_lstInvestmentTypeBudgets).AsReadOnly(); }*
>> *            protected set { _lstInvestmentTypeBudgets = value; }*
>> *        }*
>> *        public void AddBudget(Budget investment_type_budget)  {*
>> *            if (investment_type_budget != null && 
>> !_lstInvestmentTypeBudgets.Contains(investment_type_budget)){*
>> *                investment_type_budget.oInvestmentType = this; *
>> *                _lstInvestmentTypeBudgets.Add(investment_type_budget);*
>> *            }*
>> *        }*
>> *        public override int GetHashCode(){*
>> *            return (GetType().FullName + "|"+ 
>> _investmentTypeNote.GetHashCode()).GetHashCode();*
>> *        }*
>> *    }*
>>
>>
>> Budget
>> ------------------------------------------------------------------------
>>
>> <?xml version="1.0" encoding="utf-8" ?>
>>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
>>>   <class name="Tec.Core.Model.Budget, Tec.Core" table="tblBudget" 
>>> lazy="false">
>>>     <id name="ID" column="BudgetID" unsaved-value="0">
>>>       <generator class="identity" />
>>>     </id>
>>>     <property name="BudgetAmount" column="BudgetAmount" />
>>>     <property name="BudgetYear" column="BudgetYear" />
>>>     
>>>     <many-to-one name="oAirport" column="AirportID"
>>>       class="Tec.Core.Model.Airport, Tec.Core" not-null="true" />
>>>     <many-to-one name="oInvestmentCode" column="InvestmentCodeID"
>>>       class="Tec.Core.Model.InvestmentCode, Tec.Core" not-null="true" />
>>>     <many-to-one name="oInvestmentType" column="InvestmentTypeID"
>>>       class="Tec.Core.Model.InvestmentType, Tec.Core" not-null="true" /> 
>>>  
>>>     
>>>   </class>
>>> </hibernate-mapping>
>>
>>
>>
>>    * public class Budget:Entity<long> *
>> *    {*
>> *        private float _budgetAmount;*
>> *        private int _budgetYear;*
>> *        private InvestmentType _investmentType;*
>> *        private InvestmentCode _investmentCode;*
>> *        private Airport _airport;*
>>
>> *        public Budget() { }*
>> *        public float BudgetAmount** {*
>> *            get{return _budgetAmount; }*
>> *            set{_budgetAmount = value;}*
>> *        }*        
>> *        public int BudgetYear** {*
>> *            get{return _budgetYear; }*
>> *            set{_budgetYear = value;}*
>> *        }*        
>> *        public Airport oAirport**{*
>> *            get{return _airport; }*
>> *            set{_airport = value;}*
>> *        }*        
>> *        public InvestmentType oInvestmentType{*
>> *            get{return _investmentType; }*
>> *            set{_investmentType  = value;}*
>> *        }*        
>> *        public InvestmentCode oInvestmentCode {*
>> *            get{return _investmentCode ; }*
>> *            set{_investmentCode = value;}*
>> *        }*
>> *        public override int GetHashCode(){*
>> *            return (GetType().FullName + "|" + _airport.GetHashCode() 
>> +"|"+ _investmentCode.GetHashCode()+"|"+ 
>> _investmentType.GetHashCode()).GetHashCode();*
>> *        }*
>>
>> *    }*
>>
>>
>> And in my Default.asp.cs
>>
>> I have following code : 
>>
>>             Airport objA = new Airport("NA", "New Airport")
>>             InvestmentCode objIC = new InvestmentCode("1000", "ABCD");
>>             InvestmentType objIT = new InvestmentType("Capex");
>>
>>             Budget objBg = new Budget();
>>             objBg.oAirport = objA;
>>             objBg.oInvestmentCode = objIC;
>>             objBg.oInvestmentType = objIT;
>>             objBg.BudgetAmount = 10000;
>>             objBg.BudgetYear = 2014;
>>
>>             objA.AddBudget(objBg);
>>             AirportDao.SaveOrUpdate(objA);
>>
>>             objIC.AddBudget(objBg);
>> *            daoFactory.**GetInvestmentCodeDao()**.Save(*objIC*); 
>>  //Error occur here **not-null property references a null or transient 
>> value Tec.Core.Model.Budget.oInvestmentType*
>>             
>>
>>             objIT.AddBudget(objBg);            
>>             daoFactory.GetInvestmentTypeDao().Save(objIT);     
>>
>>
>> I have no idea what going on to these problem. I am very new to 
>> NHibernate and would like to start using this in my development.
>>
>> Could you please guide me how to solve this problem?
>>
>> Best regards,
>>
>> Veasna
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to