Hi,
I made a small application in Nhibernate..
my table is: CREATE TABLE [dbo].[UserInterests]( [Id] [int] IDENTITY(1,1) NOT NULL, [UserId] [int] , [InterestID] [int] ) ON [PRIMARY] and FYI this is junction table
This is my class
public class UserInterests { private int _Id; private int _userid; private IList<UserInterests> _UserInterestsList; private IList<UserInterests> _UserInterestsList2; private int _interestid; }
This is my Mapping File
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DTO" namespace="Business.Entities"> <class name="Business.Entities.UserInterests" table="UserInterests" > <id name="Id" column="Id" type="Int32" unsaved-value="null"> <generator class="identity" /> </id>
<!-- composite primary key support is touchy. View the documentation for syntax. --> <bag name="UserInterestsList" inverse="true" lazy="true" cascade="all"> <key column="UserId" /> <one-to-many class="UserInterests" /> </bag> <bag name="UserInterestsList2" inverse="true" lazy="true" cascade="all" > <key column="InterestID" /> <one-to-many class="UserInterests" /> </bag> </class> </hibernate-mapping>
and i am unable to save session with proper values public void addUserInterest(UserInterests userInterest) { try { session.Save(userInterest); session.Flush(); } catch (Exception ex) { throw ex; } }
but unfortunately Sesseion.save() didn't save data into the table... even though while debugging UserInterest contains all the data but after execution... i cant find data in the table. and got 1 Null Null 2 Null Null 3 Null Null 4 Null Null 5 Null Null just identity is working and rest of records didnt get there .... Dont know why; Can some body ans me?
|