This project is read-only.

Hibernate: refers to an unmapped class: && 1 - N relation create "enough" content parts

Topics: Customizing Orchard, Troubleshooting, Writing modules
Sep 28, 2013 at 3:57 PM
hey there,

I guess I'm having trouble with implementing my rather "complex" structure. Let me try to make the whole situation clear first:

Let's assume I have a ContentType (ContentItem) MyContentItem, which consists of two content Parts : MyPartA and MyPartB. So, when I create MyContentItem by the Admin Backend, both Part(Drivers) will become invoked after another and tried to stored to the database.

MyPartA and MyPartB are in a 1 - N relationship, within MyContentItem. The N (so the amount of how many MyPartB parts I need) is determined, due-to a property stored within MyPartA.

First of all, I thought I can use the Livecycle events (e.g. OnCreating) to create as many parts as I need. But I've encountered the problem, that within the Context I have access to within the event just has the fresh, "new" and therefore not filled MyPartA. So I can't determine how many parts I need (see the Problem here:

Afterwards I thought, I'll try it with overwriting the Updated method, but this is too late, as the model which he wants to write to the DB is already "set" and I can't modify it. Or at least, I can't see how.

Finally, here's my question: Do you have any cool tips / guidelines how I can solve my problem? I basically need to find the place within the "Orchard flow", to create as many MyPartB as I need, due-to the setting in MyPartA (so I need access to the recently "posted" data which create MyPartA).

As Orchard is having a transaction for the whole creation of the ContentItem, the data are not stored to the database yet, which obviously means I can't query them.

I'm really looking forward to your help / ideas. If this is still to hard to imagine, please let me know as well. I'll try to make it more clear :)


Sep 28, 2013 at 10:50 PM
Sep 29, 2013 at 4:08 PM
Yes, of course :)

But I can't find all answers in it. They are stating to crate the N entries immediately, by using a migration. What I need to do is: I need to create those n records (parts) within the creation of the content item. I need to find a suitable place, where I know the data of my new to create (posted data) content item to decide, how many parts of the N relationship I need to build.

From the example perspective: I'm creating MyContentItem and MyPartA is created already, but know I need to decide how many MyPartB I build based on an information stored in MyPartA.

Hope that makes it more clear :)

Sep 29, 2013 at 11:30 PM
Sep 30, 2013 at 3:19 PM
Thanks :)

I also looked trough the Demo Tutorial for ListParts ( and I've tried to implement it.

However, I'm now receiving an NHybernate Error I do not understand:
2013-09-30 16:06:55,393 [4] NHibernate.Cfg.Configuration - An association from the table Orchard_Projekt_CupRoundListPartRecord refers to an unmapped class: Orchard.Projekt.Models.CupPart
NHibernate.MappingException: An association from the table Orchard_Projekt_CupRoundListPartRecord refers to an unmapped class: Orchard.Projekt.Models.CupPart
Here's my code of the models:
    public class CupRoundListPart : ContentPart<CupRoundListPartRecord>
        private readonly LazyField<IEnumerable<CupRoundRecord>> _cupRounds = new LazyField<IEnumerable<CupRoundRecord>>();

        public CupPart Cup
            get { return Record.Cup; }
            set { Record.Cup = value; }

        public int MaxCount
            get { return Record.MaxCount; }
            set { Record.MaxCount = value; }

        public LazyField<IEnumerable<CupRoundRecord>> CupRoundsField
            get { return _cupRounds; }

        public IEnumerable<CupRoundRecord> CupRounds
            get { return _cupRounds.Value; }
    public class CupRoundListPartRecord : ContentPartRecord
        public virtual CupPart Cup { get; set; }
        public virtual int MaxCount { get; set; }

        public CupRoundListPartRecord()
            MaxCount = 10;
    public class CupRoundRecord
        public virtual int Number { get; set; }
        public virtual CupPart Cup { get; set; }
Here's my migration file as well:
       public int Create() {
            // Creating table Cups
            SchemaBuilder.CreateTable("CupRecord", table => table

                typeof(CupPart).Name, cfg => cfg.Attachable());

            // Creating table CupRound
            SchemaBuilder.CreateTable("CupRoundRecord", table => table
                .Column<int>("Id", column => column.PrimaryKey().Identity())

                typeof(CupRoundListPart).Name, cfg => cfg.Attachable());
What I want to achieve is:
Having two ContentParts "Cup" and "CupRoundListPart" which I attach to one ContentItem, where as "CupRoundListPart " has a 1 to N relationship to CupRoundRecord which are simply stored in the database and a CupRoundListPart has a reference to the Cup ContententPart.

I assume, the Hibernation Error mentioned above is an timing issue, but I'm not sure though.

Looking forward to your help.

Oct 2, 2013 at 2:00 PM
I've fixed my Hibernate Error :>