Nhibernate Conformist Mapping "Unable to determine type..."
Asked Answered
J

2

13

The class:

    public class SOPProcess : ISOPProcess
{
    public virtual Guid Id { get; set; }
    public virtual SOP SOP { get; set; }
    public virtual ProcessType Type { get; set; }       

    public virtual SOPProcessInput Input { get; set; }
    public virtual SOPProcessOutput Output { get; set; }
    public virtual SOPProcessMeasures Measures { get; set; }

    public virtual decimal YieldFactor { get; set; }

    public virtual SOPProcess PreviousProcess { get; set; }
    public virtual SOPProcess NextProcess { get; set; }
}

The Mapping:

public class SOPProcessMap : ClassMapping<SOPProcess>
{
    public SOPProcessMap()
    {
        Id(s => s.Id, i => i.Generator(Generators.GuidComb));

        Property(s => s.YieldFactor);           

        ManyToOne(s => s.SOP, m =>
                                {
                                    m.Column("SopId");
                                    m.Cascade(Cascade.All);
                                });

        ManyToOne(s => s.Type, m =>
                                {
                                    m.Column("ProcessTypeId");
                                    m.Cascade(Cascade.All);
                                });

        ManyToOne(s => s.NextProcess, m =>
                                        {
                                            m.Column("NextProcessId");
                                            m.Cascade(Cascade.All);
                                        });

        ManyToOne(s => s.PreviousProcess, m =>
                                            {
                                                m.Column("PreviousProcessId");
                                                m.Cascade(Cascade.All);
                                            });
    }
}

The Error:

NHibernate.MappingException: Could not determine type for: MES.ProcessManager.SOP.SOPProcess, MES.ProcessManager, for columns: NHibernate.Mapping.Column(id)

I hope it's something simple, this is my first project using the Conformist mapping, so maybe I'm just overlooking something.

Johnsonian answered 7/9, 2011 at 19:25 Comment(0)
B
32

From our discussion on the nhusers mailing list.

I ran across the same problems.

You haven't defined the type of relationship. See the line action => action.OneToMany()); in the mapping below.

public class SportMap : ClassMapping<Sport>
{
    public SportMap()
    {
        Id(x => x.Id, map =>
        {
            map.Column("Id");
            map.Generator(Generators.GuidComb);
        });

        Property(x => x.Name, map =>
        {
            map.NotNullable(true);
            map.Length(50);
        });

        Bag(x => x.Positions, map =>
        {
            map.Key(k => k.Column(col => col.Name("SportId")));
            map.Cascade(Cascade.All | Cascade.DeleteOrphans);
        },
        action => action.OneToMany());

        Property(x => x.CreateDate);
        Property(x => x.CreateUser);
        Property(x => x.LastUpdateDate);
        Property(x => x.LastUpdateUser);
    }
}
Behrens answered 9/9, 2011 at 15:1 Comment(5)
+1 I encountered this same problem when switching from using a ConventionModelMapper to a ModelMapper, this led me to the answer. The SimpleModelInspector figures out the action to use for each collection.Polychrome
Same here. Thanks for sharing, the error message is rather enigmatic.Caseous
So looking at @Fran's and tom.dietrich's notes, an action must be supplied for both "Bag()" and "Set()" methods. Wondering under what conditions it's allowable/useful to leave this (apparently optional) param off; if none, should be required, forcing investigation/reducing incidents of the exception altogether.Missive
@user1172173 It's not optional.Behrens
Actually it is optional, but sry shoulda been clearer (broke my own rule!). The "Set()" method is overloaded w/ a ver that excludes this param so in essence, relationship is not "required" to register a set mapping. Was wondering when it would be useful/non-trivial to do this (i.e. not know the relationship) - or even valid, esp when it's failing on this element during overall config collection validation (that part may be a bug). If no clear intent, seems there should only be the one "Set()" impl that requires the relationship.Missive
J
3

It turned out that the problem was in my Set mappings in other classes. If you don't specify the action for the mapping, it throws this (misleading) error.

Johnsonian answered 7/9, 2011 at 20:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.