Hi Patrick,
Excuse me for being so "easy", but maybe it's because of your left join ? It may return sometimes an "null Session" in your data, so that iBatis can't map it to an object ! You may activate log4net and Debug level for IBatisNet Logger to see your statements. Found on the iBatis.Net online documentation : "Lazy Loading vs. Joins (1:1) It's important to note that using a join is not always better. If you are in a situation where it is rare to access the related object (e.g. the category property of the Product class) then it might actually be faster to avoid the join and the unnecessary loading of all category properties. This is especially true for database designs that involve outer joins or nullable and/or non-indexed columns. In these situations it might be better to use the sub-select solution with lazy loading enabled. The general rule of thumb is: use the join if you're more likely going to access the associated properties than not. Otherwise, only use it if lazy loading is not an option. If you're having trouble deciding which way to go, don't worry. No matter which way you go, you can always change it without impacting your application source code. Example 3.40 and 3.41 result in exactly the same object graph and are loaded using the exact same method call from the application. The only consideration is that if you were to enable caching, then the using the separate select (not the join) solution could result in a cached instance being returned. But more often than not, that won't cause a problem (your application shouldn't be dependent on instance level equality i.e. "=="). » Hope this helps ! :-) Jérôme Avoustin -----Message d'origine----- De : Patrick Griffiths [mailto:[EMAIL PROTECTED] Envoyé : samedi 26 juillet 2008 01:54 À : [email protected] Objet : Problem mapping join on many tables to complex objects I'm trying to map from a single statement that joins 4 tables into a deep complex object layout. The result maps look like this: <resultMap id="session-result" class="Session" groupBy="SessionID"> <result property="SessionID" column="Session_SessionID"/> <!-- Rest omitted for brevity --> </resultMap> <resultMap id="class-result" class="TrainingEvent" groupBy="ClassID"> <result property="ClassID" column="Class_ClassID"/> <result property="Sessions" resultMapping="SessionSqlMap.session-result" /> <!-- Rest omitted for brevity --> </resultMap> <resultMap id="course-result" class="TrainingActivity" groupBy="CourseID"> <result property="CourseID" column="Course_CourseID"/> <result property="TrainingEvents" resultMapping="TrainingEventSqlMap.class-result"/> <!-- Rest omitted for brevity --> </resultMap> <resultMap id="company-result" class="Company" groupBy="CompanyID"> <result property="CompanyID" column="Company_CompanyID"/> <result property="TrainingActivities" resultMapping="CourseSqlMap.course-result"/> <!-- Rest omitted for brevity --> </resultMap> and the SQL is: SELECT /* fields omitted for brevity */ FROM Company c INNER JOIN Course cr ON c.CompanyID = cr.CompanyID LEFT JOIN Class cl ON cr.CourseID = cl.CourseID LEFT JOIN Session s ON cl.SessionID = cl.SessionID iBatis has no problem mapping the Company, Course and Class fields into the complex object structure, but it throws a NullReferenceException when it tries to map the fields from the Session table - even when I use the very simple abbreviated result maps above. Any help identifying where I'm going wrong would be much appreciated. Thanks.

