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.  [ 4 posts ] 
Author Message
 Post subject: Mapping columns to a Hashtable
PostPosted: Wed Apr 12, 2006 11:22 am 
Newbie

Joined: Wed Apr 12, 2006 10:58 am
Posts: 3
At compile time, we don't know all the columns that will exist in a particular table. The client my add any columns she likes and our code must read and persists data from these columns.

How can this be done?

Ideally we'd like to have a class with a Hashtable. All the dynamic column values would be stored in the Hashtable. Given a table with the columns Id, Key1, Key2, and Key3, and a class with the following definition, I'd like the values Hashtable to be loaded with each column name as a key associated with the corresponding value found in the table record.

Code:
public class GenericFields
{
   private int id;
   private Hashtable values;

   public int Id
   {
      get { return id; }
      set { id = value; }
   }

   public Hashtable Values
   {
      get { return values; }
      set { values = value; }
   }
}
<class name="GenericFields">
    <id name="Id" column="Id"/>
  // How to map columns to Hashtable?
</class>


Is this possible? If not, how could I extend NHibernate to do so?

Thanks in advance for your help,

Micah


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 3:59 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Something like this should work:
Code:
<dynamic-component name="Values">
  <property name="..." type="..." />
  <property name="..." type="..." />
</dynamic-component>

Look in the documentation for more explanations. Note that you might have to change the property type from Hashtable to IDictionary.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 9:35 pm 
Newbie

Joined: Wed Apr 12, 2006 10:58 am
Posts: 3
Cheers! Thanks a ton!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 02, 2008 8:14 am 
Newbie

Joined: Fri Jun 20, 2008 6:44 am
Posts: 1
Location: Russia
sergey wrote:
Something like this should work:
Code:
<dynamic-component name="Values">
  <property name="..." type="..." />
  <property name="..." type="..." />
</dynamic-component>

Look in the documentation for more explanations. Note that you might have to change the property type from Hashtable to IDictionary.


Hello.
Is it possible to have dynamic properties without changing the structure of the database?
Maybe xml or extension table.


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

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.