-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Adding new property at run-time to dynamic component
PostPosted: Thu Apr 15, 2010 2:19 pm 
Newbie

Joined: Thu Apr 15, 2010 1:57 pm
Posts: 9
Hello Friends,
I am new to NHibernate. We have a requirement to add new properties to the dynamic component at run-time. We are using and IDictionary in our class which we map to an dynamic component in the Nhibernate map. Here is the class definition and map, we are using (slightly modified).

public class Parent
{
public virtual long Id { get; set; }
public virtual IDictionary ExtensionData { get; set; }

public Parent()
{
ExtensionData = new Dictionary<string, object>();
}
}

<class name="Parent" table="Parent">
<id name="Id" column="Id" type="long">
<generator class="native" />
</id>
<dynamic-component name="ExtensionData" >
<property name="m_DateTime" type="DateTime" />
</dynamic-component>
</class>

As you will find that we already have a property "m_DateTime" of DateTime type in our Dictionary, and now we want to add "m_string" of String type at runtime into dynamic component. Here is the code we have for it.

NHibernate.Mapping.PersistentClass _test1 = _cfg.GetClassMapping(typeof(Parent));
NHibernate.Mapping.Property _newproperty = new NHibernate.Mapping.Property();
NHibernate.Mapping.SimpleValue _simpleValue = new NHibernate.Mapping.SimpleValue(_test1.Table);
NHibernate.Mapping.Column _newcolumn = new NHibernate.Mapping.Column("m_string");
_simpleValue.AddColumn(_newcolumn);
_simpleValue.TypeName = "string";
_newproperty.Name = "m_string";
_newproperty.Value = _simpleValue;
NHibernate.Mapping.Property _ExtensionData = _test1.GetProperty("ExtensionData");
NHibernate.Mapping.Component _compExtensionData = (NHibernate.Mapping.Component)_ExtensionData.Value;
_compExtensionData.AddProperty(_newproperty);
new SchemaUpdate(_cfg).Execute(true, true);
_cfg.BuildSessionFactory();

I am getting an exception "property mapping has wrong number of columns: " when trying to build the session factory. I appreciate any help.

Thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.