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.  [ 3 posts ] 
Author Message
 Post subject: Mapping class fields as name-value collection?
PostPosted: Sat Jan 27, 2007 3:47 am 
Newbie

Joined: Fri Nov 03, 2006 6:53 am
Posts: 5
I have the following problem.

In my program I have class like
Code:
SomethingConfiguration
{
   bool CanSomeoneMakeAction1{get;}
   bool CanSomeoneMakeAction2{get;}
   bool CanSomeoneMakeAction3{get;}
   bool CanSomeoneMakeAction4{get;}
..
   int SomeIntegerProperty{get;}
...
}


By the way number of fields in class increases - so table, associated with this class began to have overdoze of columns. There is problems with extending configuration with new property.

example:
table SomethingConfiguration
(SomethingConfigurationId, CanSomeoneMakeAction1 bit,
CanSomeoneMakeAction2 bit,
CanSomeoneMakeAction3 bit,
CanSomeoneMakeAction4 bit,
SomeIntegerProperty int
)
table contents example:
1,true,true,false,true,46

I want to store field values of this class as name-value collections in table

example:
table SomethingConfiguration
(SomethingConfigurationId, PropertyName, PropertyValue)

table contents example:
1, "CanSomeoneMakeAction1", "true"
1, "CanSomeoneMakeAction2", "true"
1, "CanSomeoneMakeAction3", "false"
1, "CanSomeoneMakeAction2", "true"
1, "SomeIntegerProperty", "46"

Can NHibernate help me do what I want?


Top
 Profile  
 
 Post subject: XML
PostPosted: Mon Jan 29, 2007 4:24 am 
Beginner
Beginner

Joined: Mon Jan 08, 2007 11:59 pm
Posts: 31
One quick (maybe dirty) way to do this would be keep the configuration in XML (and a HashMap of values in the class) and use NHibernate UserType functionality to map the values in HashMap to the XML in DB.

Hope this helps
Job Samuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 30, 2007 4:10 pm 
Beginner
Beginner

Joined: Thu Dec 21, 2006 11:38 am
Posts: 30
Look into the "component" mapping. It mentioned something about being able to treat a property as an IDictionary, which I think gives you what you want.

Here's a link to the html doc topic:
http://www.hibernate.org/hib_docs/nhibernate/html/mapping.html#mapping-declaration-component


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.