Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 1.2 beta build from source forge
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernateCETest.ProjectInclude, NHibernateCETest" table="ProjectIncludes" lazy="false">
<id name="IncludeID" column="ID" unsaved-value="0" access="field">
<generator class="native" />
</id>
<list name="ParmArr" cascade="all" table="ProjectParameters" lazy="false" inverse="true">
<key column="ProjectID" />
<index column="dex" />
<composite-element class="NHibernateCETest.ProjectParameter, NHibernateCETest">
<property name="name" column="Name" access="field"/>
<property name="val" column="Val" access="field"/>
</composite-element>
</list>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
ProjectInclude project = MakeProject();
object key = ises.Save(project);
ises.Clear();
ProjectInclude p2 = ises.Get(typeof(ProjectInclude), key) as ProjectInclude;
Assert.AreNotEqual(0, p2.ParmArr.Count, "No values returned");
Assert.IsTrue(project.Equals(p2));
Name and version of the database you are using:MS SQL Server 2005
The generated SQL (show_sql=true):Insert statement, select statement, look accurate, the problem is one that is missing.
Debug level Hibernate log excerpt:Code:
2007-01-09 17:29:06,987 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - saving [NHibernateCETest.ProjectInclude#<null>]
2007-01-09 17:29:07,050 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - executing insertions
2007-01-09 17:29:07,050 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - processing cascades for: NHibernateCETest.ProjectInclude
2007-01-09 17:29:07,050 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - done processing cascades for: NHibernateCETest.ProjectInclude
2007-01-09 17:29:07,065 [TestRunnerThread] DEBUG NHibernate.Impl.WrapVisitor [(null)] <(null)> - Wrapped collection in role: NHibernateCETest.ProjectInclude.ParmArr
2007-01-09 17:29:07,081 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Inserting entity: NHibernateCETest.ProjectInclude (native id)
2007-01-09 17:29:07,097 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened new IDbCommand, open IDbCommands: 1
2007-01-09 17:29:07,097 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Building an IDbCommand object for the SqlString: INSERT INTO ProjectIncludes DEFAULT VALUES; select SCOPE_IDENTITY()
2007-01-09 17:29:07,097 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Dehydrating entity: [NHibernateCETest.ProjectInclude#<null>]
2007-01-09 17:29:07,112 [TestRunnerThread] DEBUG NHibernate.Connection.DriverConnectionProvider [(null)] <(null)> - Obtaining IDbConnection from Driver
2007-01-09 17:29:07,456 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened IDataReader, open IDataReaders: 1
2007-01-09 17:29:07,472 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Natively generated identity: 119
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Driver.NHybridDataReader [(null)] <(null)> - running NHybridDataReader.Dispose()
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDataReader, open IDataReaders :0
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDbCommand, open IDbCommands: 0
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - processing cascades for: NHibernateCETest.ProjectInclude
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - cascading to collection: NHibernateCETest.ProjectInclude.ParmArr
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - done processing cascades for: NHibernateCETest.ProjectInclude
2007-01-09 17:29:07,503 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - loading [ProjectInclude#119]
2007-01-09 17:29:07,503 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - attempting to resolve [ProjectInclude#119]
2007-01-09 17:29:07,503 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - object not resolved in any cache [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,503 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Fetching entity: [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,503 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - loading entity: [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,518 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened new IDbCommand, open IDbCommands: 1
2007-01-09 17:29:07,518 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Building an IDbCommand object for the SqlString: SELECT projectinc0_.ID as ID0_0_ FROM ProjectIncludes projectinc0_ WHERE projectinc0_.ID=?
2007-01-09 17:29:07,534 [TestRunnerThread] INFO NHibernate.Loader.Loader [(null)] <(null)> - SELECT projectinc0_.ID as ID0_0_ FROM ProjectIncludes projectinc0_ WHERE projectinc0_.ID=@p0
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened IDataReader, open IDataReaders: 1
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - processing result set
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - result set row: 0
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - result row: 119
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - Initializing object from DataReader: [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - Hydrating entity: NHibernateCETest.ProjectInclude#119
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - done processing result set (1 rows)
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Driver.NHybridDataReader [(null)] <(null)> - running NHybridDataReader.Dispose()
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDataReader, open IDataReaders :0
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDbCommand, open IDbCommands: 0
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - total objects hydrated: 1
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - resolving associations for: [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - creating collection wrapper:[NHibernateCETest.ProjectInclude.ParmArr#119]
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - initializing collection [NHibernateCETest.ProjectInclude.ParmArr#119]
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - checking second-level cache
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - collection not cached
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - loading collection: [NHibernateCETest.ProjectInclude.ParmArr#119]
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened new IDbCommand, open IDbCommands: 1
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Building an IDbCommand object for the SqlString: SELECT parmarr0_.ProjectID as ProjectID__0_, parmarr0_.Name as Name0_, parmarr0_.Val as Val0_, parmarr0_.dex as dex__0_ FROM ProjectParameters parmarr0_ WHERE parmarr0_.ProjectID=?
2007-01-09 17:29:07,612 [TestRunnerThread] INFO NHibernate.Loader.Loader [(null)] <(null)> - SELECT parmarr0_.ProjectID as ProjectID__0_, parmarr0_.Name as Name0_, parmarr0_.Val as Val0_, parmarr0_.dex as dex__0_ FROM ProjectParameters parmarr0_ WHERE parmarr0_.ProjectID=@p0
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened IDataReader, open IDataReaders: 1
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - result set contains (possibly empty) collection: [NHibernateCETest.ProjectInclude.ParmArr#119]
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - uninitialized collection: initializing
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - processing result set
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - done processing result set (0 rows)
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Driver.NHybridDataReader [(null)] <(null)> - running NHybridDataReader.Dispose()
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDataReader, open IDataReaders :0
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDbCommand, open IDbCommands: 0
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - 1 collections were found in result set
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - collection fully initialized: [NHibernateCETest.ProjectInclude.ParmArr#119]
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - 1 collections initialized
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - done loading collection
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - collection initialized
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - done materializing entity [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - initializing non-lazy collections
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - done entity load
Code Files:
Code:
using System;
using NHibernate.Mapping.Attributes;
namespace NHibernateCETest
{
[Class(Table="ProjectParameters")]
public class ProjectParameter
{
public int parmID = 0;
public String val;
public String name;
public ProjectParameter() { }
public ProjectParameter(String nam, String val)
{
name = nam;
this.val = val;
}
}
}
Code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using NHibernate.Mapping.Attributes;
using Iesi.Collections;
namespace NHibernateCETest
{
public class ProjectInclude
{
public Dictionary<String, String> parms = new Dictionary<String, String>();
public int IncludeID = 0;
public String this[String name]
{
set { parms[name] = value; }
}
public virtual System.Collections.IList ParmArr
{
get
{
System.Collections.ArrayList al = new System.Collections.ArrayList();
foreach (String str in parms.Keys)
{
al.Add(new ProjectParameter(str, parms[str]));
}
return al;
}
set
{
foreach (ProjectParameter p in value)
{
this[p.name] = p.val;
}
}
}
}
}
Problems with Session and transaction handling?
The problem I'm having is that the ProjectInclude is not persisting the ParmArr Collection. I've tried a few dozen odd variations, and I'm certain that there is something I'm doing wrong.
Ultimately I'm trying to avoid the back reference required for a one-to-many relationship.
Can anyone see anything obviously wrong?
The ProjectInclude table consists of a Single Identity, ID, the ProjectParameters table has a ParameterID Identity, Name varchar, Val varchar, dex int, and ProjectID int.
Of Possible Note: Manually inserting the relevant data into the database results in it being read in, the only problem seems to be the first insertion.
Any thoughts?