-->
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.  [ 2 posts ] 
Author Message
 Post subject: How do I map domain values?
PostPosted: Wed Jun 28, 2006 8:21 am 
Newbie

Joined: Wed Jun 28, 2006 8:08 am
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
NHibernate 1.0.2.0

Hi.

I am wondering if it is possible to map domain values using NHibernate?

Suppose you have a table with a VARCHAR column named Enabled. This column will always have either the value 'Yes' or the value 'No'.

I would like to map this column to a bool property in C# so that 'Yes' maps to true and 'No' maps to false. Is it possible to specify this mapping?

The only workaround I have been able to find is to do the mapping in code like this:

private string enabled = "No";

public bool Enabled
{
get
{
if (enabled == "No") return false;
if (enabled == "Yes") return true;
throw...
}

set
{
if (value)
enabled = "Yes";
else
enabled = "No";
}
}

I can then map the private enabled field to the Enabled database column. I do not like this approach though as I would prefer to isolate the mapping to the database from the domain object.

Any ideas on how to do this(changing the database schema is not an option)?

Thanks in advance,
Jacob Ilsø


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 8:39 am 
Newbie

Joined: Wed Jun 28, 2006 8:08 am
Posts: 5
Hi again.

It seems I can get around it by using a custom value type. Is this the only way or is it possible to e.g. do the mapping in the xml mapping file?

Best regards,
Jacob Ilsø


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