-->
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.  [ 7 posts ] 
Author Message
 Post subject: problem with 1:n relationship and the necessary collection
PostPosted: Tue Mar 28, 2006 8:23 am 
Beginner
Beginner

Joined: Tue Mar 28, 2006 3:44 am
Posts: 22
Hi @ll,

currently I'm struggeling with a strange problem concerning an 1:n relationship between two tables. The problem is, that the collection of the "many" end objects contains (usually) the correct number of objects according to the result of the SQL-statement, but it is just filled with one object. So I have e. g. a Bag with 2 objects, but every object has the same attribute values. Although they're different in the database.
I tried to use a Bag, a Set or a List, but nothing helped. (When I'm using a List the first element (position 0) is always empty, is this by design?)

Any ideas or hints are very welcome. :)
Read on for all neccessary information...
To illustrate the different usage of Set, Bag and List I provide the Set definition as comment as well. Also I added the third table (named property) just to show the complete situation. :)

NHibernate version: 1.0.2.0

Mapping documents:
EXTERNALITEM
<?xml version='1.0' encoding='utf-8'?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ConsoleApplication1.ExternalItem, ConsoleApplication1" table="ExternalItem">
<id name="Id" type="int" column="ID" access="field.pascalcase-m-underscore">
<generator class="identity"/>
</id>
<property name="Buid" column="BUID" type="String"/>
<property name="ImportFlag" column="ImportFlag" type="String"/>
<property name="Status" column="Status" type="String"/>
<!--<set name="RelExternalItemHierarchies" table="RelExternalItemHierarchy" lazy="true" access="field.pascalcase-m-underscore">
<key column="ID" />
<composite-element class="ConsoleApplication1.RelExternalItemHierarchy, ConsoleApplication1">
<parent name="Item"/>
<many-to-one name="Hierarchy" column="HierarchyID" class="ConsoleApplication1.Hierarchy, ConsoleApplication1" />
<property name="Buid" column="BUID" />
<property name="Status" column="Status" />
<property name="Modified" column="Modified" />
</composite-element>
</set>-->
<list name="RelExternalItemHierarchies" lazy="true" access="field.pascalcase-m-underscore">
<key column="ItemID" />
<index column="ID" />
<one-to-many class="ConsoleApplication1.RelExternalItemHierarchy, ConsoleApplication1" />
</list>
<bag name="RelExternalItemProperties" lazy="true" inverse="true" access="field.pascalcase-m-underscore">
<key column="ItemID" />
<one-to-many class="ConsoleApplication1.RelExternalItemProperty, ConsoleApplication1" />
</bag>
</class>
</hibernate-mapping>

RELEXTERNALITEMHIERARCHY
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ConsoleApplication1.RelExternalItemHierarchy, ConsoleApplication1" table="RelExternalItemHierarchy">
<composite-id>
<key-many-to-one name="Item" class="ConsoleApplication1.ExternalItem, ConsoleApplication1" column="ItemID"/>
<key-many-to-one name="Hierarchy" class="ConsoleApplication1.Hierarchy, ConsoleApplication1" column="HierarchyID"/>
</composite-id>
<property name="Buid" column="BUID" type="String"/>
<property name="Status" column="Status" type="String"/>
<property name="Modified" column="Modified" type="DateTime"/>
</class>
</hibernate-mapping>

HIERARCHY
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ConsoleApplication1.Hierarchy, ConsoleApplication1" table="Hierarchy">
<id name="Id" type="Decimal" column="ID" access="field.pascalcase-m-underscore">
<generator class="identity"/>
</id>
<many-to-one name="Parent" column="ParentID" class="ConsoleApplication1.Hierarchy, ConsoleApplication1"/>
<bag name="Hierarchies" lazy="true">
<key column="ParentID"/>
<one-to-many class="ConsoleApplication1.Hierarchy, ConsoleApplication1"/>
</bag>
<property name="Buid" column="BUID" type="String"/>
<property name="HierarchyName" column="HierarchyName" type="String"/>
<property name="Status" column="Status" type="String"/>
<property name="Modified" column="Modified" type="DateTime"/>
<bag name="RelExternalItemHierarchies" inverse="true" lazy="true">
<key column="HierarchyID"/>
<one-to-many class="ConsoleApplication1.RelExternalItemHierarchy, ConsoleApplication1"/>
</bag>
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
ExternalItem testItem = (ExternalItem)session.Get(typeof(ExternalItem), 2);
//Just as a kind of debug output
Console.WriteLine("Item ID: " + testItem.Id);
foreach (RelExternalItemHierarchy exthi in testItem.RelExternalItemHierarchy)
{
//this points to a NULL value because the first element of the
//list is empty. I understand this, so that's not the real problem. :)
Console.WriteLine(exthi.Modified);
}
Console.ReadLine();
session.Close();



Name and version of the database you are using: Microsoft SQL Server 2000


The generated SQL (show_sql=true):
Selects the Item
SELECT ID AS ID0_, BUID AS BUID0_, Status AS Status0_, ImportFlag AS ImportFlag0_
FROM ExternalItem AS externalit0_
WHERE (ID = 2)

Selects the correct number of relationship entries, with the correct values!
SELECT ItemID AS ItemID__, HierarchyID AS Hierarch2___, ID AS ID__, ItemID AS ItemID0_, HierarchyID AS Hierarch2_0_, BUID AS BUID0_, Status AS Status0_,
Modified AS Modified0_
FROM RelExternalItemHierarchy AS relexterna0_
WHERE (ItemID = 2)

Selects the parent hierarchy object (foreach entry of the above resultset, so altogther twice)
SELECT hierarchy0_.ID AS ID1_, hierarchy0_.ParentID AS ParentID1_, hierarchy0_.Status AS Status1_, hierarchy0_.BUID AS BUID1_,
hierarchy0_.HierarchyName AS Hierarch4_1_, hierarchy0_.Modified AS Modified1_, hierarchy1_.ID AS ID0_, hierarchy1_.ParentID AS ParentID0_,
hierarchy1_.Status AS Status0_, hierarchy1_.BUID AS BUID0_, hierarchy1_.HierarchyName AS Hierarch4_0_,
hierarchy1_.Modified AS Modified0_
FROM Hierarchy AS hierarchy0_ LEFT OUTER JOIN
Hierarchy AS hierarchy1_ ON hierarchy0_.ParentID = hierarchy1_.ID
WHERE (hierarchy0_.ID = 3)



Debug level Hibernate log excerpt:
Here I found interesting entries, but I don't know how to interpret them. If more is needed I'll provide more debug log information.
...
What's going on here?
2006-03-28 13:59:20,476 [2348] DEBUG NHibernate.Persister.GetSetHelperFactory [(null)] - CodeDOM compilation failed
System.NullReferenceException:
in NHibernate.Persister.GetSetHelperFactory.GenerateCode()
in NHibernate.Persister.GetSetHelperFactory.CreateGetSetHelper()
...
Is this OK as "compiled ok" says?
2006-03-28 13:59:20,757 [2348] DEBUG NHibernate.Persister.GetSetHelperFactory [(null)] - Compiled ok:
using System;
using NHibernate.Property;
namespace NHibernate.Persister {
public class GetSetHelper_ConsoleApplication1_Hierarchy : IGetSetHelper {
ISetter[] setters;
IGetter[] getters;
public GetSetHelper_ConsoleApplication1_Hierarchy(ISetter[] setters, IGetter[] getters) {
this.setters = setters;
this.getters = getters;
}
public void SetPropertyValues(object obj, object[] values) {
ConsoleApplication1.Hierarchy t = (ConsoleApplication1.Hierarchy)obj;
try
{
t.Hierarchies = (System.Collections.IList)values[0];
t.Parent = (ConsoleApplication1.Hierarchy)values[1];
t.Status = (System.String)values[2];
t.Buid = (System.String)values[3];
t.HierarchyName = (System.String)values[4];
t.RelExternalItemHierarchies = (System.Collections.IList)values[5];
t.Modified = values[6] == null ? new System.DateTime() : (System.DateTime)values[6];
}
catch( InvalidCastException ice )
{
throw new MappingException(
"Invalid mapping information specified for type " + obj.GetType() + ", check your mapping file for property type mismatches",
ice);
}
}
public object[] GetPropertyValues(object obj) {
ConsoleApplication1.Hierarchy t = (ConsoleApplication1.Hierarchy)obj;
object[] ret = new object[7];
ret[0] = t.Hierarchies;
ret[1] = t.Parent;
ret[2] = t.Status;
ret[3] = t.Buid;
ret[4] = t.HierarchyName;
ret[5] = t.RelExternalItemHierarchies;
ret[6] = t.Modified;
return ret;
}
}
}

What's here?
2006-03-28 13:59:21,132 [2348] DEBUG NHibernate.SqlCommand.SqlSelectBuilder [(null)] - The initial capacity was set too low at: 8 for the SelectSqlBuilder that needed a capacity of: 12 for the table RelExternalItemHierarchy relexterna0_
2006-03-28 13:59:21,148 [2348] DEBUG NHibernate.SqlCommand.SqlSelectBuilder [(null)] - The initial capacity was set too low at: 8 for the SelectSqlBuilder that needed a capacity of: 12 for the table RelExternalItemProperty relexterna0_

2006-03-28 13:59:21,148 [2348] DEBUG NHibernate.Impl.SessionFactoryObjectFactory [(null)] - initializing class SessionFactoryObjectFactory
2006-03-28 13:59:21,148 [2348] DEBUG NHibernate.Impl.SessionFactoryObjectFactory [(null)] - registered: 2b84ace320574f51bbfe543a7927c6f9(unnamed)
2006-03-28 13:59:21,148 [2348] INFO NHibernate.Impl.SessionFactoryObjectFactory [(null)] - no name configured
2006-03-28 13:59:21,164 [2348] DEBUG NHibernate.Impl.SessionFactoryImpl [(null)] - Instantiated session factory
2006-03-28 13:59:21,195 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - opened session
2006-03-28 13:59:21,195 [2348] DEBUG NHibernate.Transaction.AdoTransaction [(null)] - begin
2006-03-28 13:59:21,211 [2348] DEBUG NHibernate.Connection.DriverConnectionProvider [(null)] - Obtaining IDbConnection from Driver
2006-03-28 13:59:21,351 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - loading [ExternalItem#2]
2006-03-28 13:59:21,367 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - attempting to resolve [ExternalItem#2]
2006-03-28 13:59:21,367 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - object not resolved in any cache [ConsoleApplication1.ExternalItem#2]
2006-03-28 13:59:21,367 [2348] DEBUG NHibernate.Persister.EntityPersister [(null)] - Materializing entity: ConsoleApplication1.ExternalItem#2
2006-03-28 13:59:21,414 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Opened new IDbCommand, open IDbCommands :1
2006-03-28 13:59:21,414 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Building an IDbCommand object for the SqlString: SELECT externalit0_.ID as ID0_, externalit0_.BUID as BUID0_, externalit0_.Status as Status0_, externalit0_.ImportFlag as ImportFlag0_ FROM ExternalItem externalit0_ WHERE externalit0_.ID=:ID
2006-03-28 13:59:21,414 [2348] DEBUG NHibernate.Type.Int32Type [(null)] - binding '2' to parameter: 0
2006-03-28 13:59:21,429 [2348] INFO NHibernate.Loader.Loader [(null)] - SELECT externalit0_.ID as ID0_, externalit0_.BUID as BUID0_, externalit0_.Status as Status0_, externalit0_.ImportFlag as ImportFlag0_ FROM ExternalItem externalit0_ WHERE externalit0_.ID=@p0
2006-03-28 13:59:21,429 [2348] DEBUG NHibernate.SQL [(null)] - SELECT externalit0_.ID as ID0_, externalit0_.BUID as BUID0_, externalit0_.Status as Status0_, externalit0_.ImportFlag as ImportFlag0_ FROM ExternalItem externalit0_ WHERE externalit0_.ID=@p0
2006-03-28 13:59:21,429 [2348] DEBUG NHibernate.SQL [(null)] - @p0 = '2'
2006-03-28 13:59:21,445 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Opened Reader, open Readers :1
2006-03-28 13:59:21,445 [2348] DEBUG NHibernate.Loader.Loader [(null)] - processing result set
2006-03-28 13:59:21,461 [2348] DEBUG NHibernate.Loader.Loader [(null)] - result row: 2
2006-03-28 13:59:21,476 [2348] DEBUG NHibernate.Loader.Loader [(null)] - Initializing object from DataReader: 2
2006-03-28 13:59:21,476 [2348] DEBUG NHibernate.Loader.Loader [(null)] - Hydrating entity: ConsoleApplication1.ExternalItem#2
2006-03-28 13:59:21,492 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning '2' as column: BUID0_
2006-03-28 13:59:21,492 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning 'D' as column: Status0_
2006-03-28 13:59:21,492 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning '1' as column: ImportFlag0_
2006-03-28 13:59:21,507 [2348] DEBUG NHibernate.Loader.Loader [(null)] - done processing result set (1 rows)
2006-03-28 13:59:21,507 [2348] DEBUG NHibernate.Driver.NHybridDataReader [(null)] - running NHybridDataReader.Dispose()
2006-03-28 13:59:21,507 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Closed Reader, open Readers :0
2006-03-28 13:59:21,507 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Closed IDbCommand, open IDbCommands :0
2006-03-28 13:59:21,507 [2348] DEBUG NHibernate.Loader.Loader [(null)] - total objects hydrated: 1
2006-03-28 13:59:21,523 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - resolving associations for: [ConsoleApplication1.ExternalItem#2]
2006-03-28 13:59:21,523 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - creating collection wrapper:[ConsoleApplication1.ExternalItem.RelExternalItemProperties#2]
2006-03-28 13:59:21,539 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - creating collection wrapper:[ConsoleApplication1.ExternalItem.RelExternalItemHierarchies#2]
2006-03-28 13:59:21,554 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - done materializing entity [ConsoleApplication1.ExternalItem#2]
2006-03-28 13:59:21,554 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - initializing non-lazy collections
2006-03-28 13:59:21,570 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - initializing collection [ConsoleApplication1.ExternalItem.RelExternalItemHierarchies#2]
2006-03-28 13:59:21,570 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - checking second-level cache
2006-03-28 13:59:21,570 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - collection not cached
2006-03-28 13:59:21,570 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Opened new IDbCommand, open IDbCommands :1
2006-03-28 13:59:21,570 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Building an IDbCommand object for the SqlString: SELECT relexterna0_.ID as ID__, relexterna0_.HierarchyID as Hierarch2___, relexterna0_.BUID as BUID__, relexterna0_.Status as Status__, relexterna0_.Modified as Modified__, hierarchy1_.ID as ID0_, hierarchy1_.ParentID as ParentID0_, hierarchy1_.Status as Status0_, hierarchy1_.BUID as BUID0_, hierarchy1_.HierarchyName as Hierarch4_0_, hierarchy1_.Modified as Modified0_, hierarchy2_.ID as ID1_, hierarchy2_.ParentID as ParentID1_, hierarchy2_.Status as Status1_, hierarchy2_.BUID as BUID1_, hierarchy2_.HierarchyName as Hierarch4_1_, hierarchy2_.Modified as Modified1_ FROM RelExternalItemHierarchy relexterna0_ left outer join Hierarchy hierarchy1_ on relexterna0_.HierarchyID=hierarchy1_.ID left outer join Hierarchy hierarchy2_ on hierarchy1_.ParentID=hierarchy2_.ID WHERE relexterna0_.ID=:ID
2006-03-28 13:59:21,570 [2348] DEBUG NHibernate.Type.Int32Type [(null)] - binding '2' to parameter: 0
2006-03-28 13:59:21,570 [2348] INFO NHibernate.Loader.Loader [(null)] - SELECT relexterna0_.ID as ID__, relexterna0_.HierarchyID as Hierarch2___, relexterna0_.BUID as BUID__, relexterna0_.Status as Status__, relexterna0_.Modified as Modified__, hierarchy1_.ID as ID0_, hierarchy1_.ParentID as ParentID0_, hierarchy1_.Status as Status0_, hierarchy1_.BUID as BUID0_, hierarchy1_.HierarchyName as Hierarch4_0_, hierarchy1_.Modified as Modified0_, hierarchy2_.ID as ID1_, hierarchy2_.ParentID as ParentID1_, hierarchy2_.Status as Status1_, hierarchy2_.BUID as BUID1_, hierarchy2_.HierarchyName as Hierarch4_1_, hierarchy2_.Modified as Modified1_ FROM RelExternalItemHierarchy relexterna0_ left outer join Hierarchy hierarchy1_ on relexterna0_.HierarchyID=hierarchy1_.ID left outer join Hierarchy hierarchy2_ on hierarchy1_.ParentID=hierarchy2_.ID WHERE relexterna0_.ID=@p0
2006-03-28 13:59:21,570 [2348] DEBUG NHibernate.SQL [(null)] - SELECT relexterna0_.ID as ID__, relexterna0_.HierarchyID as Hierarch2___, relexterna0_.BUID as BUID__, relexterna0_.Status as Status__, relexterna0_.Modified as Modified__, hierarchy1_.ID as ID0_, hierarchy1_.ParentID as ParentID0_, hierarchy1_.Status as Status0_, hierarchy1_.BUID as BUID0_, hierarchy1_.HierarchyName as Hierarch4_0_, hierarchy1_.Modified as Modified0_, hierarchy2_.ID as ID1_, hierarchy2_.ParentID as ParentID1_, hierarchy2_.Status as Status1_, hierarchy2_.BUID as BUID1_, hierarchy2_.HierarchyName as Hierarch4_1_, hierarchy2_.Modified as Modified1_ FROM RelExternalItemHierarchy relexterna0_ left outer join Hierarchy hierarchy1_ on relexterna0_.HierarchyID=hierarchy1_.ID left outer join Hierarchy hierarchy2_ on hierarchy1_.ParentID=hierarchy2_.ID WHERE relexterna0_.ID=@p0
2006-03-28 13:59:21,570 [2348] DEBUG NHibernate.SQL [(null)] - @p0 = '2'
2006-03-28 13:59:21,586 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Opened Reader, open Readers :1
2006-03-28 13:59:21,586 [2348] DEBUG NHibernate.Loader.Loader [(null)] - result set contains (possibly empty) collection: [ConsoleApplication1.ExternalItem.RelExternalItemHierarchies#2]
2006-03-28 13:59:21,586 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - uninitialized collection: initializing
2006-03-28 13:59:21,586 [2348] DEBUG NHibernate.Loader.Loader [(null)] - processing result set
2006-03-28 13:59:21,586 [2348] DEBUG NHibernate.Type.DecimalType [(null)] - returning '7' as column: ID0_
2006-03-28 13:59:21,586 [2348] DEBUG NHibernate.Type.DecimalType [(null)] - returning '5' as column: ID1_
2006-03-28 13:59:21,586 [2348] DEBUG NHibernate.Loader.Loader [(null)] - result row: 7, 5
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Loader.Loader [(null)] - Initializing object from DataReader: 7
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Loader.Loader [(null)] - Hydrating entity: ConsoleApplication1.Hierarchy#7
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.DecimalType [(null)] - returning '5' as column: ParentID0_
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning 'A' as column: Status0_
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning 'dfg' as column: BUID0_
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning 'dfhgdfg' as column: Hierarch4_0_
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.DateTimeType [(null)] - returning '10.01.2000' as column: Modified0_
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Loader.Loader [(null)] - Initializing object from DataReader: 5
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Loader.Loader [(null)] - Hydrating entity: ConsoleApplication1.Hierarchy#5
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.DecimalType [(null)] - returning '1' as column: ParentID1_
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning 'D' as column: Status1_
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning 'abc' as column: BUID1_
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning 'mähmähhhh' as column: Hierarch4_1_
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.DateTimeType [(null)] - returning '22.03.2006' as column: Modified1_
2006-03-28 13:59:21,601 [2348] DEBUG NHibernate.Type.Int32Type [(null)] - returning '2' as column: ID__
2006-03-28 13:59:21,617 [2348] DEBUG NHibernate.Loader.Loader [(null)] - found row of collection: [ConsoleApplication1.ExternalItem.RelExternalItemHierarchies#2]
2006-03-28 13:59:21,617 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - reading row
2006-03-28 13:59:21,617 [2348] DEBUG NHibernate.Type.DecimalType [(null)] - returning '7' as column: Hierarch2___
2006-03-28 13:59:21,617 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning '1' as column: BUID__
2006-03-28 13:59:21,617 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning 'A' as column: Status__
2006-03-28 13:59:21,617 [2348] DEBUG NHibernate.Type.DateTimeType [(null)] - returning '10.10.2001' as column: Modified__
2006-03-28 13:59:21,617 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - loading [Hierarchy#7]
2006-03-28 13:59:21,617 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - attempting to resolve [Hierarchy#7]
2006-03-28 13:59:21,632 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - resolved object in session cache [ConsoleApplication1.Hierarchy#7]
2006-03-28 13:59:21,632 [2348] DEBUG NHibernate.Loader.Loader [(null)] - done processing result set (1 rows)
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Driver.NHybridDataReader [(null)] - running NHybridDataReader.Dispose()
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Closed Reader, open Readers :0
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Closed IDbCommand, open IDbCommands :0
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Loader.Loader [(null)] - total objects hydrated: 2
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - resolving associations for: [ConsoleApplication1.Hierarchy#7]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - creating collection wrapper:[ConsoleApplication1.Hierarchy.Hierarchies#7]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - loading [Hierarchy#5]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - attempting to resolve [Hierarchy#5]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - resolved object in session cache [ConsoleApplication1.Hierarchy#5]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - creating collection wrapper:[ConsoleApplication1.Hierarchy.RelExternalItemHierarchies#7]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - done materializing entity [ConsoleApplication1.Hierarchy#7]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - resolving associations for: [ConsoleApplication1.Hierarchy#5]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - creating collection wrapper:[ConsoleApplication1.Hierarchy.Hierarchies#5]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - loading [Hierarchy#1]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - attempting to resolve [Hierarchy#1]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - object not resolved in any cache [ConsoleApplication1.Hierarchy#1]
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Persister.EntityPersister [(null)] - Materializing entity: ConsoleApplication1.Hierarchy#1
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Opened new IDbCommand, open IDbCommands :1
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Building an IDbCommand object for the SqlString: SELECT hierarchy0_.ID as ID1_, hierarchy0_.ParentID as ParentID1_, hierarchy0_.Status as Status1_, hierarchy0_.BUID as BUID1_, hierarchy0_.HierarchyName as Hierarch4_1_, hierarchy0_.Modified as Modified1_, hierarchy1_.ID as ID0_, hierarchy1_.ParentID as ParentID0_, hierarchy1_.Status as Status0_, hierarchy1_.BUID as BUID0_, hierarchy1_.HierarchyName as Hierarch4_0_, hierarchy1_.Modified as Modified0_ FROM Hierarchy hierarchy0_ left outer join Hierarchy hierarchy1_ on hierarchy0_.ParentID=hierarchy1_.ID WHERE hierarchy0_.ID=:ID
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.Type.DecimalType [(null)] - binding '1' to parameter: 0
2006-03-28 13:59:21,648 [2348] INFO NHibernate.Loader.Loader [(null)] - SELECT hierarchy0_.ID as ID1_, hierarchy0_.ParentID as ParentID1_, hierarchy0_.Status as Status1_, hierarchy0_.BUID as BUID1_, hierarchy0_.HierarchyName as Hierarch4_1_, hierarchy0_.Modified as Modified1_, hierarchy1_.ID as ID0_, hierarchy1_.ParentID as ParentID0_, hierarchy1_.Status as Status0_, hierarchy1_.BUID as BUID0_, hierarchy1_.HierarchyName as Hierarch4_0_, hierarchy1_.Modified as Modified0_ FROM Hierarchy hierarchy0_ left outer join Hierarchy hierarchy1_ on hierarchy0_.ParentID=hierarchy1_.ID WHERE hierarchy0_.ID=@p0
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.SQL [(null)] - SELECT hierarchy0_.ID as ID1_, hierarchy0_.ParentID as ParentID1_, hierarchy0_.Status as Status1_, hierarchy0_.BUID as BUID1_, hierarchy0_.HierarchyName as Hierarch4_1_, hierarchy0_.Modified as Modified1_, hierarchy1_.ID as ID0_, hierarchy1_.ParentID as ParentID0_, hierarchy1_.Status as Status0_, hierarchy1_.BUID as BUID0_, hierarchy1_.HierarchyName as Hierarch4_0_, hierarchy1_.Modified as Modified0_ FROM Hierarchy hierarchy0_ left outer join Hierarchy hierarchy1_ on hierarchy0_.ParentID=hierarchy1_.ID WHERE hierarchy0_.ID=@p0
2006-03-28 13:59:21,648 [2348] DEBUG NHibernate.SQL [(null)] - @p0 = '1'
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Opened Reader, open Readers :1
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Loader.Loader [(null)] - processing result set
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Type.DecimalType [(null)] - returning '1' as column: ID0_
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Loader.Loader [(null)] - result row: 1, 1
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Loader.Loader [(null)] - Initializing object from DataReader: 1
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Loader.Loader [(null)] - Hydrating entity: ConsoleApplication1.Hierarchy#1
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Type.DecimalType [(null)] - returning '1' as column: ParentID0_
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning 'D' as column: Status0_
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning '1' as column: BUID0_
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Type.StringType [(null)] - returning 'Hallo' as column: Hierarch4_0_
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Type.DateTimeType [(null)] - returning '21.02.2006' as column: Modified0_
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Loader.Loader [(null)] - done processing result set (1 rows)
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Driver.NHybridDataReader [(null)] - running NHybridDataReader.Dispose()
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Closed Reader, open Readers :0
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Closed IDbCommand, open IDbCommands :0
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Loader.Loader [(null)] - total objects hydrated: 1
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - resolving associations for: [ConsoleApplication1.Hierarchy#1]
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - creating collection wrapper:[ConsoleApplication1.Hierarchy.Hierarchies#1]
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - loading [Hierarchy#1]
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - attempting to resolve [Hierarchy#1]
2006-03-28 13:59:21,726 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - resolved object in session cache [ConsoleApplication1.Hierarchy#1]
2006-03-28 13:59:21,742 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - creating collection wrapper:[ConsoleApplication1.Hierarchy.RelExternalItemHierarchies#1]
2006-03-28 13:59:21,742 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - done materializing entity [ConsoleApplication1.Hierarchy#1]
2006-03-28 13:59:21,742 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - creating collection wrapper:[ConsoleApplication1.Hierarchy.RelExternalItemHierarchies#5]
2006-03-28 13:59:21,742 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - done materializing entity [ConsoleApplication1.Hierarchy#5]
2006-03-28 13:59:21,742 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - 1 collections were found in result set
2006-03-28 13:59:21,757 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - collection fully initialized: [ConsoleApplication1.ExternalItem.RelExternalItemHierarchies#2]
2006-03-28 13:59:21,757 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - 1 collections initialized
2006-03-28 13:59:21,757 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - initializing non-lazy collections
2006-03-28 13:59:21,757 [2348] DEBUG NHibernate.Impl.SessionImpl [(null)] - collection initialized


I guess that's all for now.
Hope this helps and someone can provide a hint, would be very great! :)

Many thanks in advance,
Chavez


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 9:00 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
For lazy loading to work properly, all public methods and properties must be declared as virtual. Are they in implementation?

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 9:15 am 
Beginner
Beginner

Joined: Tue Mar 28, 2006 3:44 am
Posts: 22
gert wrote:
For lazy loading to work properly, all public methods and properties must be declared as virtual. Are they in implementation?

Now they are. ;) Thanks for this important hint even though it didn't solve my problem so far.

Chavez


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 9:33 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Ok, there is one inconsitencey I found:


RELEXTERNALITEMHIERARCHY defines id to be composite-id, but ExternalItem uses single column in the list name="RelExternalItemHierarchies" definition.

I have never used composite keys so I do not klnow how would be the correct definition. Maybe Your's is correct (thought it seems illogical)...

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 9:51 am 
Beginner
Beginner

Joined: Tue Mar 28, 2006 3:44 am
Posts: 22
gert wrote:
Ok, there is one inconsitencey I found:

RELEXTERNALITEMHIERARCHY defines id to be composite-id, but ExternalItem uses single column in the list name="RelExternalItemHierarchies" definition.


Thanks! :) This solves one part of the problem! :)
I changed the table definition to avoid a composite primary key and added a surrogate key but I _didn't_ change all mappings as well. Too bad. But you helped me out! :)

Just one question is left... Why is the first item in the List empty ? Position 0 is null, position 1 and 2 are filled with a RelExternalItemHierarchy object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 10:46 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Chavez2K2 wrote:
gert wrote:
Just one question is left... Why is the first item in the List empty ? Position 0 is null, position 1 and 2 are filled with a RelExternalItemHierarchy object.


What does Your database table contain in Index column? If 0 is present, then it is propably a bug. If not, the it is propably "by design" - to indicate that there was null item in that position in the list at the save moment.

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 4:14 am 
Beginner
Beginner

Joined: Tue Mar 28, 2006 3:44 am
Posts: 22
Your hint pointed me in the right direction. :)
The use of list in the mapping file causes the mentioned behavior. And this is of course right because it's a list. :) I switched from list to bag and now everything is alright.

Thanks again for your help gert! :)

Greetings,
Chavez


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.