AutoMap, Inheritance and Reference

88 views
Skip to first unread message

Jose Selesan

unread,
May 18, 2009, 12:08:30 PM5/18/09
to fluent-n...@googlegroups.com
Hi people. I'm becoming crazy with a problem. I have classes like theese:

public class Entity
{
   public virtual int Id { get; protected set; }
}

public class Person: Entity
{
   public virtual string Name{ get; set; }
}

public class Foto: Entity
{
  public virtual DateTime DateTaken{ get; set; }
}

public class PersonFoto: Foto
{
   public virtual Person Person{ get; set; }
}

And I'm configuring my PersistenceModel like this:

            AutoPersistenceModel p = AutoPersistenceModel
                .MapEntitiesFromAssemblyOf<Entity>()
                .WithSetup(s =>
                {
                    s.IsBaseType = i => i == typeof(Entity);
                });


            Fluently.Configure().Database(MsSqlConfiguration.MsSql2005.ConnectionString(t => t.Is("server=fsgestioner; uid=sa; pwd=sa; database=samples")))
                .Mappings(
                    m => m.AutoMappings.Add(p)
                   ).BuildSessionFactory();

But when NHibernate is creating the session factory, It throws an exception with this stack trace:


   en NHibernate.Mapping.Column.set_Name(String value)
   en NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindColumns(XmlNode node, SimpleValue model, Boolean isNullable, Boolean autoColumn, String propertyPath)
   en NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindManyToOne(XmlNode node, ManyToOne model, String defaultColumnName, Boolean isNullable)
   en NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode node, PersistentClass model)
   en NHibernate.Cfg.XmlHbmBinding.JoinedSubclassBinder.HandleJoinedSubclass(PersistentClass model, XmlNode subnode)
   en NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode node, PersistentClass model)
   en NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node, HbmClass classSchema)
   en NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode parentNode)
   en NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node)
   en NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)

The courious case is that I write my PersonFoto to this:

public class PersonFoto: Foto {
   public virtual string Person{get; set; }
}

It works!!!
Can anybody help me? I tried to override mappings, but without success.

Thanks in advance

James Gregory

unread,
May 18, 2009, 1:09:50 PM5/18/09
to fluent-n...@googlegroups.com
When was the last time you did an update?

Jose Selesan

unread,
May 18, 2009, 1:18:55 PM5/18/09
to fluent-n...@googlegroups.com
Last week, on firday

Jon M

unread,
May 21, 2009, 4:43:56 AM5/21/09
to Fluent NHibernate
I'm getting the exact same problem. My classes are similar:

public class JobAttachment : Entity
{
public virtual Job Job { get; set; }
public virtual DateTime CreatedDate { get; set; }
public virtual User CreatedBy { get; set; }
}

public class ImageAttachment : JobAttachment
{
public virtual string Description { get; set; }
public virtual ImageData Thumbnail { get; set; }
public virtual ImageDate FullSize { get; set; }
}

public class ImageData : Entity
{
public virtual string MimeType { get; set; }
public virtual byte[] Data { get; set; }
}

Setup code is more or less identical:
sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(x => x.Is
(connectionString)).ShowSql())
.Mappings(m =>
{
m.AutoMappings.Add(AutoPersistenceModel
.MapEntitiesFromAssemblyOf<Entity>()
.Where(x => typeof(Entity).IsAssignableFrom(x))
.WithSetup(x =>
{
x.IsBaseType = t => t == typeof(Entity);
}
})
.ExposeConfiguration(c => c.Properties.Add
("proxyfactory.factory_class",
"NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle"))
.BuildSessionFactory();

I updated from SVN last night (20th May).

On May 18, 6:18 pm, Jose Selesan <jsele...@gmail.com> wrote:
> Last week, on firday
>
> On Mon, May 18, 2009 at 2:09 PM, James Gregory <jagregory....@gmail.com>wrote:
>
> > When was the last time you did an update?
>

Paul Batum

unread,
May 22, 2009, 9:15:20 AM5/22/09
to fluent-n...@googlegroups.com
What is the message for the exception? This is typically more useful than the stack trace..

Also, Jon, is this part of your mapping correct?


public class ImageAttachment : JobAttachment
{
   public virtual string Description { get; set; }
   public virtual ImageData Thumbnail { get; set; }
   public virtual ImageDate FullSize { get; set; }
}

Or should the fullsize property be a ImageData rather than ImageDate?

Jon M

unread,
May 22, 2009, 10:41:02 AM5/22/09
to Fluent NHibernate
The message I get is as follows:

FluentNHibernate.Cfg.FluentConfigurationException : An invalid or
incomplete configuration was used while creating a SessionFactory.
Check PotentialReasons collection, and InnerException for more detail.

----> FluentNHibernate.Cfg.FluentConfigurationException : An invalid
or incomplete configuration was used while creating a SessionFactory.
Check PotentialReasons collection, and InnerException for more detail.

----> NHibernate.MappingException : Could not compile the mapping
document: (XmlDocument)
----> System.IndexOutOfRangeException : Index was outside the bounds
of the array.

When I caught the exception in the debugger, the PotentialReasons
collection was empty.

Yes that ImageDate was a typo on my part, good catch!
Jon


On 22 May, 14:15, Paul Batum <paul.ba...@gmail.com> wrote:
> What is the message for the exception? This is typically more useful than
> the stack trace..
>
> Also, Jon, is this part of your mapping correct?
>
> public class ImageAttachment : JobAttachment
> {
>    public virtual string Description { get; set; }
>    public virtual ImageData Thumbnail { get; set; }
>    public virtual ImageDate FullSize { get; set; }
>
> }
>
> Or should the fullsize property be a ImageData rather than ImageDate?
>

Stuart Childs

unread,
May 22, 2009, 10:45:59 AM5/22/09
to fluent-n...@googlegroups.com
I've most often seen the "Index was outside the bounds of the array" exception when column names were missing. Can you export your mappings with a .ExportTo("path") and look through them or post them here?

Jon M

unread,
May 23, 2009, 7:57:17 AM5/23/09
to Fluent NHibernate
Stuart, looks like the column name is missing for those properties:

<joined-subclass name="MyProj.Core.Domain.ImageAttachment,
MyProj.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<key column="JobAttachmentId" />
<property name="Description">
<column name="Description" />
</property>
<many-to-one name="Thumbnail" column="" />
<many-to-one name="FullSize" column="" />
</joined-subclass>

What could cause them to be empty?
Jon


On 22 May, 15:45, Stuart Childs <chil...@gmail.com> wrote:
> I've most often seen the "Index was outside the bounds of the array"
> exception when column names were missing. Can you export your mappings with
> a .ExportTo("path") and look through them or post them here?
>

oliver klemencic

unread,
May 23, 2009, 11:57:54 AM5/23/09
to Fluent NHibernate
I have had the same problem and traced the error to the fact, that the
default conventions are not used for the AutoJoinedSubClass.
Until now I haven't fully understood the Fluent- Nhibernate source
code, so I could not fix this problem on my one.

Jon M

unread,
May 23, 2009, 2:47:04 PM5/23/09
to Fluent NHibernate
Oliver - were you able to write a custom convention or anything to get
around it?

oliver klemencic

unread,
May 24, 2009, 3:41:11 PM5/24/09
to Fluent NHibernate
As I said.. I currently don't understand all the code...

I took a look at
BaseMappingPartDiscoveryConvention<TPart>.ApplyConventions when it
gets called for the part which has the auto- joined- subclasses.
None of the conventions returned by
DefaultConventionFinder.Find<IMappingPartConvention>() handles the
auto-joined- subclass parts.

Maybe we need a convention which accepts AutoJoinedSubClass- parts and
applies all the default- convention for the sub- parts of the
AutoJoinedSubclass.

Martin Hornagold

unread,
May 25, 2009, 6:36:58 PM5/25/09
to fluent-n...@googlegroups.com
This is because AutoJoinedSubclass does not implement IJoinedSubclass.
I raised this wayback and submitted a patch, but it never got applied.
Until this is fixed you can't use conventions with AutoJoinedSubclass

Jon M

unread,
May 25, 2009, 7:23:27 PM5/25/09
to Fluent NHibernate
So, sorry if this is a stupid question, does that mean that there's no
way to use automapping for subclasses at all?

On May 25, 11:36 pm, "Martin Hornagold"
> ...
>
> read more »

James Gregory

unread,
May 26, 2009, 3:58:23 AM5/26/09
to fluent-n...@googlegroups.com
It sounds like it, unless you apply Martin's patch yourself. I'm not sure why this has been missed so I (or one of the other devs if they read this, hint hint) will try to fix this ASAP.

James Gregory

unread,
May 26, 2009, 3:46:15 PM5/26/09
to fluent-n...@googlegroups.com
I've just committed a fix for this, let me know if there's any further issues with it.

Jon M

unread,
May 27, 2009, 3:02:07 PM5/27/09
to Fluent NHibernate
All working nicely now, thanks James!

On May 26, 8:46 pm, James Gregory <jagregory....@gmail.com> wrote:
> I've just committed a fix for this, let me know if there's any further
> issues with it.
>
> On Tue, May 26, 2009 at 8:58 AM, James Gregory <jagregory....@gmail.com>wrote:
>
>
>
> > It sounds like it, unless you apply Martin's patch yourself. I'm not sure
> > why this has been missed so I (or one of the other devs if they read this,
> > hint hint) will try to fix this ASAP.
>
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages