Hello,
I need help implementing NHibernate (which is awesome by the way). I've been reading the documentation and following examples for the past few working days and have everything working just fine. It wasn't until we introduced a "bag" (to map a collection) that things went sour.
I apologize for not reading ALL of the forum. When I search for my specific problem, I get 2000+ topics returned! (if you want to help me at a lower level, how do you search "using quotes" to group search terms?)
The error i get is:
NHibernate.AssertionFailure : null id in entry (don't flush the Session after an exception occurs)
I know this must be user error. I am pretty sure it is the mapping file that is bad. As I have been staring at it for three days, it "looks" correct to me. Can someone please suggest a way for me to diagnose this problem?
I've tried following the WilsonNHibernateExample (got it working no problem). It also uses a "bag". Emulating the setup in Wilson's demo doesnt seem to work for me!
I apologize in advance for being an NHibernate newb. I've tried best I can to solve this particular problem. I could really use some assistance!
Thanks,
Tom
C#, Windows XP Pro, VS .NET, fancy computer, local database.
Hibernate version:
nhibernate-0.9.0.0
Mapping documents:
<?xml version='1.0' encoding='utf-8'?>
<hibernate-mapping
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='urn:nhibernate-mapping-2.0'>
<!-- Chip.cs mapping. Contains a collection called ChipHistory -->
<class
name='Pgic.Its.Domain.Chip, Pgic.Its.Domain'
table='ChipInventory'>
<id
name='UniqueId'
column='ChipSerial'
type='Int32'>
<generator
class='assigned' />
</id>
<property
name='Denomination'
type='double'
column='ChipValue' />
<bag name="ChipHistory" table="ChipHistory" cascade="all" lazy="true" inverse="true" >
<key column="ChipSerial" />
<one-to-many class="Pgic.Its.Domain.ChipHistoryEntry, Pgic.Its.Domain" />
</bag>
</class>
<!-- ChipHistory. Is a Many-to-One Collection Mapping. Collection housed in Chip.cs. -->
<class
name='Pgic.Its.Domain.ChipHistoryEntry, Pgic.Its.Domain'
table='ChipHistory'>
<id name='ChipSerial'
column='ChipSerial'
type='Int32'
length='20' >
<generator
class='identity' />
</id>
<property
name='User'
type='String'
column='UserName' />
<property
name='IpAddress'
type='String'
column='UserIpAddress' />
<property
name='Message'
type='String'
column='Message' />
<!--<many-to-one name="ChipHistory" column="ChipSerial" class="Pgic.Its.Domain.Chip, Pgic.Its.Domain" cascade="all" />
<many-to-one name="ChipSerial" column="ChipSerial" class="Pgic.Its.Domain.Chip, Pgic.Its.Domain" cascade="all" />-->
<many-to-one name="Chip" column="ChipSerial" class="Pgic.Its.Domain.Chip, Pgic.Its.Domain" cascade="all" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
try
{
ISession session = DBSessionManager.SessionFactory.OpenSession();
ITransaction transaction = session.BeginTransaction();
try
{
foreach (Chip chip in _list)
{
session.SaveOrUpdateCopy(chip);
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
transaction.Commit();
session.Close();
}
catch (NHibernate.ADOException e)
{
Console.Write(e);
}
Full stack trace of any exception that occurs:
at NHibernate.Impl.SessionImpl.CheckId(Object obj, IClassPersister persister, Object id)
at NHibernate.Impl.SessionImpl.FlushEntity(Object obj, EntityEntry entry)
at NHibernate.Impl.SessionImpl.FlushEntities()
at NHibernate.Impl.SessionImpl.FlushEverything()
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()
at Pgic.Its.Domain.Commands.SaveChipCommand.Execute() in c:\documents and settings\owner\my documents\visual studio projects\its\pgic.its.domain\commands\savechipcommand.cs:line 52
at
Name and version of the database you are using:
SQL Server 2003
Classes involved:
Chip.cs // id property is "UniqueId"
ChipHistoryEntry.cs // id property is "ChipSerial" (same as UniqeId, diff name)
and Chip.cs contains:
private IList _chipHistory = new ArrayList();
public IList ChipHistory
{
get
{
return _chipHistory;
}
set
{
_chipHistory = value;
}
}
|