Hello everybody,

I just started looking into NHibernate to see if we can use it as the
ORM solution for a new project.

One requirement we have is to support an adaptive domain model, where
there is a core part which is strongly typed but each customer can
adapt the schema to include information that is pertinent only for his
installation.

I'm very happy to see that this mechanism is supported in NHibernate
through the <dynamic-component> mapping.

There is one use case that I have not managed to cover, namely to have
a collection as an element of the dynamic component. For my test I
used a "Person" class with an IDictionary to contain the extension
data:

[Serializable]
public  class Person
{
    private Int32 id;
    private DateTime birthday;
    private IDictionary extensionData = new Hashtable();

    public Person() {}

    public virtual Int32 Id
    {
        get { return this.id; }
        set { this.id = value; }
    }

    public virtual DateTime Birthday
    {
        get { return this.birthday; }
        set { this.birthday = value; }
    }

    public virtual IDictionary ExtensionData
    {
        get { return this.extensionData; }
        set { this.extensionData = value; }
    }
}

The corresponding mapping file definition is:

  <class name="Person">
    <id name="Id" column="Id" unsaved-value="0">
      <generator class="native"/>
    </id>

    <property name="Birthday" type="date"/>

    <join table="PersonExtensions" optional="true">
      <key column="PersonId"/>
      <dynamic-component name="ExtensionData">
        <property name="Nickname" type="string"/>

        <set generic="true" name="Hobbies" table="PersonHobbies">
          <key column="PersonId"/>
          <element column="Value" type="string"/>
        </set>
      </dynamic-component>
    </join>
  </class>

I hoped to get the ISet<string> collection into my dictionary, but I
get an exception at setup, when the hbm.xml document is added to the
configuration. The stack trace is at the end of this post.

Has anybody tried something similar? I don't know if the use of
collections inside dynamic components is supported, if I'm doing
something wrong or if it is a bug.
Any help on this would be very welcome.

Thank you very much,
Nicola

System.NullReferenceException: Object reference not set to an instance
of an object.
at
NHibernate.Cfg.XmlHbmBinding.CollectionBinder.BindCollection(XmlNode
node, Collection model, String className, String path, Type
containingType)
at NHibernate.Cfg.XmlHbmBinding.CollectionBinder.CreateSet(XmlNode
node, String prefix, String path, PersistentClass owner, Type
containingType)
at NHibernate.Cfg.XmlHbmBinding.CollectionBinder.Create(String
xmlTagName, XmlNode node, String className, String path,
PersistentClass owner, Type containingType)
at NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindComponent(XmlNode
node, Component model, Type reflectedClass, String className, String
path, Boolean isNullable)
at NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindJoin(XmlNode node,
Join join)
at NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode
node, PersistentClass model)
at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node,
HbmClass classSchema)
at
NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode
parentNode)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node)
at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument
doc)
NHibernate.MappingException: Could not compile the mapping document:
YapsNh.Mappings.YapsNh.Domain.DynamicExtensions.hbm.xml
at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument
doc)
at NHibernate.Cfg.Configuration.ProcessMappingsQueue()
at
NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument
document)
at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader,
String name)
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream,
String name)
at NHibernate.Cfg.Configuration.AddResource(String path, Assembly
assembly)
at
YapsNh.Tests.DynamicExtensions.DynamicExtensions_Fixture.TestFixtureSetUp()
in DynamicExtensions_Fixture.cs: line 28


--~--~---------~--~----~------------~-------~--~----~
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