Repeated column in mapping for collection exception ... Why?

231 views
Skip to first unread message

wgp...@gmail.com

unread,
Mar 17, 2009, 9:10:54 PM3/17/09
to Fluent NHibernate
Getting this exception:

NHibernate.MappingException: Repeated column in mapping for
collection: TrainingDB.Core.Division.Ancestors column: DivisionID

Here is what my CONFIGURATION looks like:

private void GetConventions(Conventions c)
{
c.GetTableName = type => Inflector.Net.Inflector.Pluralize(type.Name);
c.IsBaseType = IsBaseTypeConvention;
c.GetPrimaryKeyNameFromType = type => type.Name + "ID";
c.FindIdentity = type => type.Name == "Id";
c.GetForeignKeyNameOfParent = type => type.Name + "ID";

c.OneToManyConvention = o => o.Cascade.All();

c.GetManyToManyTableName = ((child, parent) => parent.Name +
Inflector.Net.Inflector.Pluralize(child.Name));
}


Here is what my CLASS looks like:

using NHibernate.Validator.Constraints;
using SharpArch.Core;
using SharpArch.Core.DomainModel;
using System.Collections.Generic;

namespace TrainingDB.Core
{
public class Division: Entity
{
public Division()
{
InitMembers();
}
public Division(string abbr, string name) : this()
{
Check.Require(!string.IsNullOrEmpty(abbr) && !string.IsNullOrEmpty
(name) && abbr.Trim() != string.Empty && name.Trim() != string.Empty,
"Abbreviation and a Name must be provided");

this.Abbr = abbr;
this.Name = name;
}

#region Persisted Properties

[DomainSignature]
[NotNullNotEmpty(Message = "An abbreviation must be provided")]
public virtual string Abbr { get; set; }

[DomainSignature]
[NotNullNotEmpty(Message = "Name must be provided")]
public virtual string Name { get; set; }

public virtual string ADName { get; set; }

public virtual int? MailCode { get; set; }

public virtual int? HomeDeptCode { get; set; }

public virtual Division ParentDivision { get; protected set; }

public virtual string ProjectNumber { get; set; }

public virtual string Description { get; set; }

public virtual int DisplayOrder { get; set; }

public virtual int Depth { get; set; }

public virtual string Path { get; set; }

public virtual IList<Division> ChildDivisions { get; protected
set; }

public virtual IList<Index> Indexes { get; protected set; }

public virtual IList<User> Users { get; protected set; }

#endregion

#region Other Properites

List<Division> ancestors;
public virtual IList<Division> Ancestors
{
get
{
ancestors = ancestors ?? GetAncestors(this);
return ancestors;
}
}

#endregion

#region Methods

public virtual void AddChildDivision(Division o)
{
if (!this.ChildDivisions.Contains(o)) {
o.ParentDivision = this;
this.ChildDivisions.Add(o);
}
}
public virtual void RemoveChildDivision(Division o)
{
if (this.ChildDivisions.Contains(o)) {
o.ParentDivision = null;
this.ChildDivisions.Remove(o);
}
}

public virtual void AddIndex(Index o)
{
if (!this.Indexes.Contains(o)) {
o.Division = this;
this.Indexes.Add(o);
}
}
public virtual void RemoveIndex(Index o)
{
if (this.Indexes.Contains(o)) {
o.Division = null;
this.Indexes.Remove(o);
}
}

public virtual void AddUser(User o)
{
if (!this.Users.Contains(o)) {
o.Division = this;
this.Users.Add(o);
}
}
public virtual void RemoveUser(User o)
{
if (this.Users.Contains(o)) {
o.Division = null;
this.Users.Remove(o);
}
}

#endregion

/// <summary>
/// Since we want to leverage automatic properties, init appropriate
members here.
/// </summary>
private void InitMembers()
{
ChildDivisions = new List<Division>();
Indexes = new List<Index>();
Users = new List<User>();
}
private List<Division> GetAncestors(Division d)
{
List<Division> ancestors = new List<Division>();

if (d.ParentDivision != null) {
ancestors.Add(d.ParentDivision);
ancestors.AddRange(GetAncestors(d.ParentDivision));
}

return ancestors;
}
}
}


....


Here is what my TABLE looks like:

Table Name: Divisions
Columns: DivisionID (pk,int, not-null), ParentDivisionID (fk, int,
null), .... <a bunch of other columns>

....

What am I missing and/or doing wrong here? The "Ancestors" property
it is complaining about isn't mapped to anything. Its simply a helper
method to traverse up the parent/child hierarchy based on the
ParentDivisionID column.

Thanks!
Reply all
Reply to author
Forward
0 new messages