-->
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.  [ 3 posts ] 
Author Message
 Post subject: null id in entry - need help with error
PostPosted: Mon Feb 06, 2006 8:48 pm 
Newbie

Joined: Mon Feb 06, 2006 8:12 pm
Posts: 2
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;
}
}


Top
 Profile  
 
 Post subject: Assigned
PostPosted: Tue Feb 07, 2006 1:50 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
The code in SessionImpl that throws the exception checks if the Id property is set on the object which you are trying to save. I noticed that you are using
<generator
class='assigned' />
</id>
for Chip class. Are you sure you have set the UniqueId property before calling save because NHib will assume that the Id property will be set by the user as you are using the ASSIGNED.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 12:09 pm 
Regular
Regular

Joined: Tue May 24, 2005 12:55 pm
Posts: 56
It would be nice if the error could say which class the id is null on. I think I'm getting this error on a cascaded item, but the log doesn't show cascading has started. Can this happen on properties that are NotNull=true?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.