Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 1.2.0 Beta 3 (one from a few days ago)
Mapping documents:
ProjectInclude:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateCETest" assembly="NHibernateCETest">
<class name="ProjectInclude" table="ProjectIncludes" lazy="false">
<id name="IncludeID" column="ID" unsaved-value="0" access="field">
<generator class="native" />
</id>
<map name="ParmArr" cascade="all" table="ParameterIndex" access="field" lazy="false">
<key column="ProjectID" />
<index-many-to-many column="ParameterID" class="ProjectParameter" />
<element column="keyCol" type="String"/>
</map>
</class>
</hibernate-mapping>
Project Parameter:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateCETest" assembly="NHibernateCETest">
<class name="ProjectParameter" table="ProjectParameters" lazy="false">
<id name="parmID" column="ParameterID" unsaved-value="0" access="field">
<generator class="native" />
</id>
<property name="name" column="Name" access="field"/>
<property name="val" column="Val" access="field"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Exception causing:
Code:
ProjectInclude project = MakeProject();
ises.SaveOrUpdate(project);
ises.Flush();
Exception free:
Code:
ProjectInclude project = MakeProject();
ises.SaveOrUpdate(project);
foreach (ProjectParameter p in project.ParmArr.Keys)
ises.SaveOrUpdate(p);
ises.Flush();
ProjectInclude.cs
Code:
public class ProjectInclude
{
public IDictionary ParmArr=new Hashtable();
public int IncludeID = 0;
public String this[String name]
{
set
{
ProjectParameter t=new ProjectParameter(name, value);
ParmArr[t] = name;
}
}
public int Count
{
get { return ParmArr.Count; }
}
public override bool Equals(object obj)
{
ProjectInclude pi = obj as ProjectInclude;
return pi.ParmArr.Count == ParmArr.Count;
}
public override int GetHashCode()
{
return ParmArr.Count;
}
}
Full stack trace of any exception that occurs:Code:
at NHibernate.Impl.SessionImpl.ThrowTransientObjectException(Object obj) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3748
at NHibernate.Impl.SessionImpl.GetEntityIdentifierIfNotUnsaved(Object obj) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3737
at NHibernate.Type.EntityType.GetIdentifier(Object value, ISessionImplementor session) in c:\net\nhibernate\nhibernate\src\NHibernate\Type\EntityType.cs:line 80
at NHibernate.Type.ManyToOneType.NullSafeSet(IDbCommand cmd, Object value, Int32 index, ISessionImplementor session) in c:\net\nhibernate\nhibernate\src\NHibernate\Type\ManyToOneType.cs:line 69
at NHibernate.Persister.Collection.AbstractCollectionPersister.WriteIndex(IDbCommand st, Object idx, Int32 i, ISessionImplementor session) in c:\net\nhibernate\nhibernate\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 603
at NHibernate.Persister.Collection.AbstractCollectionPersister.Recreate(IPersistentCollection collection, Object id, ISessionImplementor session) in c:\net\nhibernate\nhibernate\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 936
at NHibernate.Impl.ScheduledCollectionRecreate.Execute() in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\ScheduledCollectionRecreate.cs:line 32
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3264
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3243
at NHibernate.Impl.SessionImpl.Execute() in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3181
at NHibernate.Impl.SessionImpl.Flush() in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3015
at NHibernateCETest.CETestFixture.SaveThrowsNoException() in C:\Documents and Settings\mattmoss\Desktop\ESL Lookup\NHibernateCETest\CETestFixture.cs:line 45
Name and version of the database you are using: MSSQL 2005
The generated SQL (show_sql=true): Not Relevant
Debug level Hibernate log excerpt: Code:
2007-01-11 14:15:19,471 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - unsaved-value: 0
2007-01-11 14:15:19,502 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - SaveOrUpdate() unsaved instance
2007-01-11 14:15:19,502 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - saving [NHibernateCETest.ProjectInclude#<null>]
2007-01-11 14:15:19,517 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - executing insertions
2007-01-11 14:15:19,517 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - processing cascades for: NHibernateCETest.ProjectInclude
2007-01-11 14:15:19,517 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - done processing cascades for: NHibernateCETest.ProjectInclude
2007-01-11 14:15:19,533 [TestRunnerThread] DEBUG NHibernate.Impl.WrapVisitor [(null)] <(null)> - Wrapped collection in role: NHibernateCETest.ProjectInclude.ParmArr
2007-01-11 14:15:19,533 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Inserting entity: NHibernateCETest.ProjectInclude (native id)
2007-01-11 14:15:19,549 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened new IDbCommand, open IDbCommands: 1
2007-01-11 14:15:19,549 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Building an IDbCommand object for the SqlString: INSERT INTO ProjectIncludes DEFAULT VALUES; select SCOPE_IDENTITY()
2007-01-11 14:15:19,549 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Dehydrating entity: [NHibernateCETest.ProjectInclude#<null>]
2007-01-11 14:15:19,549 [TestRunnerThread] DEBUG NHibernate.Connection.DriverConnectionProvider [(null)] <(null)> - Obtaining IDbConnection from Driver
2007-01-11 14:15:19,705 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened IDataReader, open IDataReaders: 1
2007-01-11 14:15:19,736 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Natively generated identity: 1
2007-01-11 14:15:19,736 [TestRunnerThread] DEBUG NHibernate.Driver.NHybridDataReader [(null)] <(null)> - running NHybridDataReader.Dispose()
2007-01-11 14:15:19,736 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDataReader, open IDataReaders :0
2007-01-11 14:15:19,736 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDbCommand, open IDbCommands: 0
2007-01-11 14:15:19,736 [TestRunnerThread] DEBUG NHibernate.Impl.ConnectionManager [(null)] <(null)> - aggressively releasing database connection
2007-01-11 14:15:19,736 [TestRunnerThread] DEBUG NHibernate.Connection.ConnectionProvider [(null)] <(null)> - Closing connection
2007-01-11 14:15:19,752 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - processing cascades for: NHibernateCETest.ProjectInclude
2007-01-11 14:15:19,752 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - done processing cascades for: NHibernateCETest.ProjectInclude
2007-01-11 14:15:19,752 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - flushing session
2007-01-11 14:15:19,752 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - processing cascades for: NHibernateCETest.ProjectInclude
2007-01-11 14:15:19,752 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - done processing cascades for: NHibernateCETest.ProjectInclude
2007-01-11 14:15:19,752 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - Flushing entities and processing referenced collections
2007-01-11 14:15:19,767 [TestRunnerThread] DEBUG NHibernate.Impl.AbstractVisitor [(null)] <(null)> - Processing collection for role NHibernateCETest.ProjectInclude.ParmArr
2007-01-11 14:15:19,767 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - Collection found: [NHibernateCETest.ProjectInclude.ParmArr#1], was: [<unreferenced>]
2007-01-11 14:15:19,767 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - Processing unreferenced collections
2007-01-11 14:15:19,767 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - scheduling collection removes/(re)creates/updates
2007-01-11 14:15:19,767 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
2007-01-11 14:15:19,767 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
2007-01-11 14:15:19,767 [TestRunnerThread] DEBUG NHibernate.Impl.Printer [(null)] <(null)> - listing entities:
2007-01-11 14:15:19,783 [TestRunnerThread] DEBUG NHibernate.Impl.Printer [(null)] <(null)> - NHibernateCETest.ProjectInclude{IncludeID=1, ParmArr=[BLDG4:1, BLDG3]}
2007-01-11 14:15:19,783 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - executing flush
2007-01-11 14:15:19,783 [TestRunnerThread] DEBUG NHibernate.Impl.ConnectionManager [(null)] <(null)> - registering flush begin
2007-01-11 14:15:19,783 [TestRunnerThread] DEBUG NHibernate.Persister.Collection.ICollectionPersister [(null)] <(null)> - Inserting collection: [NHibernateCETest.ProjectInclude.ParmArr#1]
2007-01-11 14:15:19,799 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened new IDbCommand, open IDbCommands: 1
2007-01-11 14:15:19,799 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Building an IDbCommand object for the SqlString: INSERT INTO ParameterIndex (ProjectID, ParameterID, keyCol) VALUES (?, ?, ?)
2007-01-11 14:15:19,799 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - unsaved-value: 0
2007-01-11 14:15:19,799 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDbCommand, open IDbCommands: 0
2007-01-11 14:15:19,799 [TestRunnerThread] DEBUG NHibernate.Impl.ConnectionManager [(null)] <(null)> - skipping aggressive-release due to flush cycle
2007-01-11 14:15:19,799 [TestRunnerThread] ERROR NHibernate.Impl.SessionImpl [(null)] <(null)> - could not synchronize database state with session
NHibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: NHibernateCETest.ProjectParameter
at NHibernate.Impl.SessionImpl.ThrowTransientObjectException(Object obj) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3748
at NHibernate.Impl.SessionImpl.GetEntityIdentifierIfNotUnsaved(Object obj) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3737
at NHibernate.Type.EntityType.GetIdentifier(Object value, ISessionImplementor session) in c:\net\nhibernate\nhibernate\src\NHibernate\Type\EntityType.cs:line 80
at NHibernate.Type.ManyToOneType.NullSafeSet(IDbCommand cmd, Object value, Int32 index, ISessionImplementor session) in c:\net\nhibernate\nhibernate\src\NHibernate\Type\ManyToOneType.cs:line 69
at NHibernate.Persister.Collection.AbstractCollectionPersister.WriteIndex(IDbCommand st, Object idx, Int32 i, ISessionImplementor session) in c:\net\nhibernate\nhibernate\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 603
at NHibernate.Persister.Collection.AbstractCollectionPersister.Recreate(IPersistentCollection collection, Object id, ISessionImplementor session) in c:\net\nhibernate\nhibernate\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 936
at NHibernate.Impl.ScheduledCollectionRecreate.Execute() in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\ScheduledCollectionRecreate.cs:line 32
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3264
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list) in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3243
at NHibernate.Impl.SessionImpl.Execute() in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3175
2007-01-11 14:15:19,846 [TestRunnerThread] DEBUG NHibernate.Impl.ConnectionManager [(null)] <(null)> - registering flush end
2007-01-11 14:15:19,846 [TestRunnerThread] DEBUG NHibernate.Impl.ConnectionManager [(null)] <(null)> - aggressively releasing database connection
Problems with Session and transaction handling?
I'm unsure of how much of that will actually be needed, but, none the less.
The ProjectInclude file has an IDictionairy that maps an instance of ProjectParameter to a String. When I attempt to save (and then flush) a normal ProjectInclude instance, it throws the exception above. If I manually go through and save the keys before flushing the session, it works. Is there anyway to have NHibernate take care of saving the keys? (I though setting cascade="all" would have, though it seems I was mistaken...). Any ideas? Anything obviously wrong with the mapping file?