/// <remarks>
		/// Called for all collections
		/// </remarks>
		public static void BindCollection( XmlNode node, Mapping.Collection model, string className, string path, Mappings mappings )
		{
			//ROLENAME
			model.Role = StringHelper.Qualify( className, path );

			XmlAttribute inverseNode = node.Attributes[ "inverse" ];
			if( inverseNode != null )
			{
				model.IsInverse = StringHelper.BooleanValue( inverseNode.Value );
			}

			XmlAttribute orderNode = node.Attributes[ "order-by" ];
			if( orderNode != null )
			{
				model.OrderBy = orderNode.Value;
			}
			XmlAttribute whereNode = node.Attributes[ "where" ];
			if( whereNode != null )
			{
				model.Where = whereNode.Value;
			}
			XmlAttribute batchNode = node.Attributes[ "batch-size" ];
			if( batchNode != null )
			{
				model.BatchSize = Int32.Parse( batchNode.Value );
			}

			//PERSISTER
			XmlAttribute persisterNode = node.Attributes[ "persister" ];
			if( persisterNode == null )
			{
				//persister = CollectionPersisterImpl.class;
			}
			else
			{
				model.CollectionPersisterClass = ClassForNameChecked(
					persisterNode.Value, mappings,
					"could not instantiate collection persister class: {0}" );
			}

			InitOuterJoinFetchSetting( node, model );

			XmlNode oneToManyNode = node.SelectSingleNode( nsOneToMany, nsmgr );
			if( oneToManyNode != null )
			{
				OneToMany oneToMany = new OneToMany( model.Owner );
				model.Element = oneToMany;
				BindOneToMany( oneToManyNode, oneToMany, mappings );
				//we have to set up the table later!! yuck
			}
			else
			{
				//TABLE
				XmlAttribute tableNode = node.Attributes[ "table" ];
				string tableName;
				if( tableNode != null )
				{
					tableName = mappings.NamingStrategy.TableName( tableNode.Value );
				}
				else
				{
					tableName = mappings.NamingStrategy.PropertyToTableName( className, path );
				}
				XmlAttribute schemaNode = node.Attributes[ "schema" ];
				string schema = schemaNode == null ? mappings.SchemaName : schemaNode.Value;
				model.CollectionTable = mappings.AddTable( schema, tableName );

				log.Info( "Mapping collection: " + model.Role + " -> " + model.CollectionTable.Name );
			}

			//LAZINESS
			XmlAttribute lazyNode = node.Attributes[ "lazy" ];
			if( lazyNode != null )
			{
				model.IsLazy = StringHelper.BooleanValue( lazyNode.Value );
			}

			//SORT
			XmlAttribute sortedAtt = node.Attributes[ "sort" ];
			// unsorted, natural, comparator.class.name
			if( sortedAtt == null || sortedAtt.Value.Equals( "unsorted" ) )
			{
				model.IsSorted = false;
			}
			else
			{
				model.IsSorted = true;
				string comparatorClassName = FullClassName( sortedAtt.Value, mappings );
				if( !comparatorClassName.Equals( "natural" ) )
				{
					try
					{
						model.Comparer = ( IComparer ) Activator.CreateInstance( ReflectHelper.ClassForName( comparatorClassName ) );
					}
					catch
					{
						throw new MappingException( "could not instantiate comparer class: " + comparatorClassName );
					}
				}
			}

			//ORPHAN DELETE (used for programmer error detection)
			XmlAttribute cascadeAtt = node.Attributes[ "cascade" ];
			if( cascadeAtt != null && cascadeAtt.Value.Equals( "all-delete-orphan" ) )
			{
				model.OrphanDelete = true;
			}

			//set up second pass
			if( model is List )
			{
				mappings.AddSecondPass( new ListSecondPass( node, mappings, ( List ) model ) );
			}
			else if( model is Map )
			{
				mappings.AddSecondPass( new MapSecondPass( node, mappings, ( Map ) model ) );
			}
			else if( model is Set )
			{
				mappings.AddSecondPass( new SetSecondPass( node, mappings, ( Set ) model ) );
			}
			else if( model is IdentifierCollection )
			{
				mappings.AddSecondPass( new IdentifierCollectionSecondPass( node, mappings, ( IdentifierCollection ) model ) );
			}
			else
			{
				mappings.AddSecondPass( new CollectionSecondPass( node, mappings, model ) );
			}
		}
		private static void BindResultSetMappingDefinition(XmlNode resultSetElem, string path, Mappings mappings)
		{
			mappings.AddSecondPass(new ResultSetMappingSecondPass(resultSetElem, path, mappings, nsmgr));
		}
		/// <remarks>
		/// Called for all collections. <paramref name="containingType" /> parameter
		/// was added in NH to allow for reflection related to generic types.
		/// </remarks>
		public static void BindCollection(XmlNode node, Mapping.Collection model, string className, string path,
		                                  System.Type containingType, Mappings mappings)
		{
			// ROLENAME
			model.Role = StringHelper.Qualify(className, path);
			// TODO: H3.1 has just collection.setRole(path) here - why?

			XmlAttribute inverseNode = node.Attributes["inverse"];
			if (inverseNode != null)
			{
				model.IsInverse = StringHelper.BooleanValue(inverseNode.Value);
			}

			// TODO: H3.1 - not ported: mutable
			XmlAttribute olNode = node.Attributes["optimistic-lock"];
			model.IsOptimisticLocked = olNode == null || "true".Equals(olNode.Value);

			XmlAttribute orderNode = node.Attributes["order-by"];
			if (orderNode != null)
			{
				model.OrderBy = orderNode.Value;
			}
			XmlAttribute whereNode = node.Attributes["where"];
			if (whereNode != null)
			{
				model.Where = whereNode.Value;
			}
			XmlAttribute batchNode = node.Attributes["batch-size"];
			if (batchNode != null)
			{
				model.BatchSize = Int32.Parse(batchNode.Value);
			}

			// PERSISTER
			XmlAttribute persisterNode = node.Attributes["persister"];
			if (persisterNode == null)
			{
				//persister = CollectionPersisterImpl.class;
			}
			else
			{
				model.CollectionPersisterClass = ClassForNameChecked(
					persisterNode.Value, mappings,
					"could not instantiate collection persister class: {0}");
			}

			XmlAttribute typeNode = node.Attributes["collection-type"];
			if (typeNode != null)
			{
				model.TypeName = typeNode.Value;
			}

			// FETCH STRATEGY
			InitOuterJoinFetchSetting(node, model);

			if ("subselect".Equals(XmlHelper.GetAttributeValue(node, "fetch")))
			{
				model.IsSubselectLoadable = true;
				model.Owner.HasSubselectLoadableCollections = true;
			}

			// LAZINESS
			InitLaziness(node, model, mappings, "true", mappings.DefaultLazy);
			// TODO: H3.1 - lazy="extra"

			XmlNode oneToManyNode = node.SelectSingleNode(HbmConstants.nsOneToMany, nsmgr);
			if (oneToManyNode != null)
			{
				OneToMany oneToMany = new OneToMany(model.Owner);
				model.Element = oneToMany;
				BindOneToMany(oneToManyNode, oneToMany, mappings);
				//we have to set up the table later!! yuck
			}
			else
			{
				//TABLE
				XmlAttribute tableNode = node.Attributes["table"];
				string tableName;
				if (tableNode != null)
				{
					tableName = mappings.NamingStrategy.TableName(tableNode.Value);
				}
				else
				{
					tableName = mappings.NamingStrategy.PropertyToTableName(className, path);
				}
				XmlAttribute schemaNode = node.Attributes["schema"];
				string schema = schemaNode == null ? mappings.SchemaName : schemaNode.Value;
				model.CollectionTable = mappings.AddTable(schema, tableName);

				log.Info("Mapping collection: " + model.Role + " -> " + model.CollectionTable.Name);
			}

			//SORT
			XmlAttribute sortedAtt = node.Attributes["sort"];
			// unsorted, natural, comparator.class.name
			if (sortedAtt == null || sortedAtt.Value.Equals("unsorted"))
			{
				model.IsSorted = false;
			}
			else
			{
				model.IsSorted = true;
				if (!sortedAtt.Value.Equals("natural"))
				{
					string comparatorClassName = FullClassName(sortedAtt.Value, mappings);
					try
					{
						model.Comparer = Activator.CreateInstance(ReflectHelper.ClassForName(comparatorClassName));
					}
					catch
					{
						throw new MappingException("could not instantiate comparer class: " + comparatorClassName);
					}
				}
			}

			//ORPHAN DELETE (used for programmer error detection)
			XmlAttribute cascadeAtt = node.Attributes["cascade"];
			if (cascadeAtt != null && cascadeAtt.Value.Equals("all-delete-orphan"))
			{
				model.OrphanDelete = true;
			}


			bool? isGeneric = null;

			XmlAttribute genericAtt = node.Attributes["generic"];
			if (genericAtt != null)
			{
				isGeneric = bool.Parse(genericAtt.Value);
			}

			System.Type collectionType = null;

			if (!isGeneric.HasValue)
			{
				collectionType = GetPropertyType(node, mappings, containingType, GetPropertyName(node));
				isGeneric = collectionType.IsGenericType;
			}

			model.IsGeneric = isGeneric ?? false;

			if (model.IsGeneric)
			{
				// Determine the generic arguments using reflection
				if (collectionType == null)
				{
					collectionType = GetPropertyType(node, mappings, containingType, GetPropertyName(node));
				}
				System.Type[] genericArguments = collectionType.GetGenericArguments();
				model.GenericArguments = genericArguments;
			}
			HandleCustomSQL(node, model);

			//set up second pass
			if (model is List)
			{
				mappings.AddSecondPass(new ListSecondPass(node, mappings, (List) model));
			}
			else if (model is Map)
			{
				mappings.AddSecondPass(new MapSecondPass(node, mappings, (Map) model));
			}
			else if (model is Set)
			{
				mappings.AddSecondPass(new SetSecondPass(node, mappings, (Set) model));
			}
			else if (model is IdentifierCollection)
			{
				mappings.AddSecondPass(new IdentifierCollectionSecondPass(node, mappings, (IdentifierCollection) model));
			}
			else
			{
				mappings.AddSecondPass(new CollectionSecondPass(node, mappings, model));
			}

			foreach (XmlNode filter in node.SelectNodes(HbmConstants.nsFilter, nsmgr))
			{
				ParseFilter(filter, model, mappings);
			}

			XmlNode loader = node.SelectSingleNode(HbmConstants.nsLoader, nsmgr);
			if (loader != null)
			{
				model.LoaderName = XmlHelper.GetAttributeValue(loader, "query-ref");
			}
		}
		private static void BindNamedSQLQuery(XmlNode queryElem, string path, Mappings mappings)
		{
			mappings.AddSecondPass(new NamedSQLQuerySecondPass(queryElem, path, mappings, nsmgr));
			/*
			string qname = queryElem.Attributes["name"].Value;
			NamedSQLQuery namedQuery = new NamedSQLQuery(queryElem.InnerText);

			foreach (XmlNode returns in queryElem.SelectNodes(nsReturn, nsmgr))
			{
				string alias = returns.Attributes["alias"].Value;
				System.Type clazz = ClassForNameChecked(
					returns.Attributes["class"].Value, mappings,
					"class not found: {0} for alias " + alias);
				namedQuery.AddAliasedClass(alias, clazz);
			}

			foreach (XmlNode table in queryElem.SelectNodes(nsSynchronize, nsmgr))
			{
				namedQuery.AddSynchronizedTable(table.Attributes["table"].Value);
			}

			log.Debug("Named sql query: " + qname + " -> " + namedQuery.QueryString);
			mappings.AddSQLQuery(qname, namedQuery);
			*/
		}