Modus Operandi
Modus Operandi

Reputation: 641

Fluent NHibernate: No persister for error

Been frustrated over this for the last hour, can't understand it.

There's a class, Message:

public class Message : IEntity {
    public virtual int Id { get; set; }
    public virtual Sender Sender { get; set; }
}

Then there's the Sender class, which I want to be stored as a component for (same table as) Message:

public class Sender : IEntityComponent {
    public virtual String Person { get; set; }
    public virtual String RawInfo { get; set; }
}

I'm configuring NHibernate with:

public class StorageConfiguration : DefaultAutomappingConfiguration {
    public override bool ShouldMap(Type type)
    {
        return type.GetInterfaces().Any(t => t == typeof(IEntity) || t == typeof(IEntityComponent));
    }

    public override bool IsComponent(Type type)
    {
        return type.GetInterfaces().Contains(typeof(IEntityComponent));
    }

    public override string GetComponentColumnPrefix(FluentNHibernate.Member member)
    {
        return member.PropertyType.Name + "_";
    }
}

Now here's what I don't get. NHibernate creates a 100% correct database structure:

create table `Messages` (
   `Id` INTEGER NOT NULL AUTO_INCREMENT,
   `Sender_Person` VARCHAR(255),
   `Sender_RawInfo` VARCHAR(255),
   primary key (`Id`)
)

But when I try to actually save a Message record into the database, I get this exception:

No persister for: Www.Entities.Sender

All search results end up with "class must be public" or "you are not loading the correct assembly". I have checked and re-checked those and it seems to me they couldn't even be the reason in this case because the database is created successfully and contains the correct table & columns.

UPDATE: Adding/removing

public class MessageMap : IAutoMappingOverride<Message> {
    public void Override(AutoMapping<Message> mapping)
    {
        mapping.Component(m => m.Sender, s => {
            s.Map(m => m.Person);
            s.Map(m => m.RawInfo);
        });
    }
}

changes nothing.

Upvotes: 1

Views: 2599

Answers (1)

Modus Operandi
Modus Operandi

Reputation: 641

OK, I might be a bit of an idiot. :D I was trying to save the Sender object on its own, not as a property of a Message object. A more descriptive error would have helped to realize it sooner, though.

Upvotes: 1

Related Questions