Hey Everyone,

I've asked the question on the FluentNHibernate list already, so if
you're a member of both I apologize for the dupe.

I have an abstract base class that has 3 concrete implementations.
I've setup the mapping using Joined-SubClass and cannot get any of the
objects to persist. Whenever I do a Session.Save(obj) for an object of
one of the concrete types I get this exception:
NHibernate.PropertyAccessException: Exception occurred getter of
Domain.Entities.BaseEntity.Id
and the target exception is
System.Reflection.TargetException: Object does not match target type.
Which is weird because that same Id is being used for all the other
types that extend BaseEntity.

Here's a pseudo coded smaple:
// Classes
public abstract class BaseEntity
{
    public virtual int Id { get; protected set; }
}

public class User : BaseEntity
{
    public User()
    {
        Items = new List<Item>();
    }

    public virtual string Name { get; set; }
    public virtual IList<Item> Items { get; set; }
}

public abstract class Item : BaseEntity
{
    public virtual string Name { get; set; }
    public virtual User User { get; set; }
}

And here are the maps.  I used FluentNH but I checked the mapping
files that were created and everything looks correct.

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Id(x => x.Id).GeneratedBy.Native();
        Map(x => x.Name);
        HasMany(x => x.Items).Cascade.AllDeleteOrphan();
    }
}

public class ItemMap : ClassMap<Item>
{
    public ItemMap()
    {
        Id(x => x.Id).ColumnName("ItemId").GeneratedBy.Native();

        Map(x => x.IsActive);
        References(x => x.User);

        JoinedSubClass<Item_A>("ItemId", sub => sub.Map(x =>
x.A_property));
        JoinedSubClass<Item_B>("ItemId", sub => sub.Map(x =>
x.B_property));
        JoinedSubClass<Item_C>("ItemId", sub => sub.Map(x =>
x.C_property));
    }
}

Many thanks,
Rob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to