<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>NHibernate</title>
        <link>http://www.statichippo.com/category/4.aspx</link>
        <description>NHibernate</description>
        <language>en-US</language>
        <copyright>Noah</copyright>
        <generator>Subtext Version 2.1.2.2</generator>
        <item>
            <title>Mapping Serializable types using Fluent NHibernate</title>
            <link>http://statichippo.com/archive/2010/01/20/mapping-serializable-types-using-fluent-nhibernate.aspx</link>
            <description>&lt;p&gt;Yesterday I posted a question to StackOverflow (&lt;a title="http://stackoverflow.com/questions/2097364/mapping-to-serializabletype-in-fluent-nhibernate" href="http://stackoverflow.com/questions/2097364/mapping-to-serializabletype-in-fluent-nhibernate"&gt;http://stackoverflow.com/questions/2097364/mapping-to-serializabletype-in-fluent-nhibernate&lt;/a&gt;) asking whether anyone could tell me how to map a Serializable type using Fluent NHibernate.  The outcome was disappointing to say the least.  In 24 hours there have been less than 20 views.  It was voted up twice, but no comments or answers were posted.&lt;/p&gt;  &lt;p&gt;Even worse, there’s another post on StackOverflow (&lt;a title="http://stackoverflow.com/questions/2000798/map-to-serializable-in-fluent-nhibernate" href="http://stackoverflow.com/questions/2000798/map-to-serializable-in-fluent-nhibernate"&gt;http://stackoverflow.com/questions/2000798/map-to-serializable-in-fluent-nhibernate&lt;/a&gt;) that asks this same question and has an answer that’s incorrect (it compiles but throws an exception at runtime).&lt;/p&gt;  &lt;h3&gt;Serializable types in NHibernate (XML)&lt;/h3&gt;  &lt;p&gt;Before I continue, I’ll give a little background.  Feel free to skip this part.  Suppose you want to map the following object (contrived, I know):&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 90%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Person&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; FirstName { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; LastName { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; BirthCertificate BirthCertificate { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 90%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BirthCertificate&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; DateTime DOB { get; set;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; BirthCity { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; BirthState { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; HospitalName { get; set;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Imagine, however, that you don’t want to map the BirthCertificate fields to a table.  Imagine you want to serialize the BirthCertificate object and store it in a single column in the Person table.&lt;/p&gt;

&lt;p&gt;NHibernate makes this really easy.  When mapping the BirthCertificate property on Person, you would write something like this:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 90%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="BirthCertificate"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;column&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="BirthCertificate"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Serializable"&lt;/span&gt;  &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;and of course you would have to add a [Serializable] attribute to the BirthCertificate class like so:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 90%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; [Serializable]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BirthCertificate&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; .......&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;Mapping Serializable using Fluent NHibernate&lt;/h3&gt;

&lt;p&gt;This is actually surprisingly easy.&lt;/p&gt;

&lt;p&gt;The Fluent interface provides a &lt;strong&gt;CustomType&lt;/strong&gt; method that allows you to map your entity to a custom, IUserType.  The incorrect answer that was posted on the &lt;em&gt;old&lt;/em&gt; StackOverflow post (link above) mentioned combining this CustomType method with the SerializableType type, like this:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 90%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; CustomType&amp;lt;NHibernate.Type.SerializableType&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;That will build, but it throws an Exception at runtime:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;InnerException:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Could not instantiate IType SerializableType: System.MissingMethodException: No parameterless constructor defined for this object.
    &lt;br /&gt;   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp;amp; canBeCached, RuntimeMethodHandle&amp;amp; ctor, Boolean&amp;amp; bNeedSecurityCheck)

    &lt;br /&gt;   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)

    &lt;br /&gt;   at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)

    &lt;br /&gt;   at System.Activator.CreateInstance(Type type, Boolean nonPublic)

    &lt;br /&gt;   at System.Activator.CreateInstance(Type type)

    &lt;br /&gt;   at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type)

    &lt;br /&gt;   at NHibernate.Type.TypeFactory.HeuristicType(String typeName, IDictionary`2 parameters)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I’m not a contributor to the Fluent NHibernate project (though I’m considering it after some other things calm down and I have more time), so I wasn’t particularly familiar with the codebase.  In order to find the solution, I downloaded the latest code and stepped through it to see how it works.&lt;/p&gt;

&lt;p&gt;Basically, the fluent interface collects all your mapping settings and then outputs the appropriate hbm’s at configure-time.  Using the incorrect answer above resulted in the following mapping for the BirthCertificate property:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 90%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &amp;lt;property name=&lt;span style="color: #006080"&gt;"BirthCertificate"&lt;/span&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; type=&lt;span style="color: #006080"&gt;"NHibernate.Type.SerializableType, NHibernate, &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4"&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;   &amp;lt;column name=&lt;span style="color: #006080"&gt;"`BirthCertificate`"&lt;/span&gt; /&amp;gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; &amp;lt;/property&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p /&gt;

&lt;p /&gt;

&lt;p /&gt;

&lt;p&gt;Hey – that should read &lt;strong&gt;type=”Serializable”&lt;/strong&gt;!  We don’t want the whole Type info there!&lt;/p&gt;

&lt;p&gt;Turns out one of the overloads of the &lt;strong&gt;CustomType&lt;/strong&gt; method takes….. you guessed it (!)…. a &lt;strong&gt;String&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;The following is the correct way of mapping a Serializable type in Fluent NHibernate&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 90%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; CustomType(&lt;span style="color: #006080"&gt;"Serializable"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Yes I feel stupid for not figuring this out from the start!  One comfort though is that it doesn’t seem that many people know this, even though it seems so obvious.&lt;/p&gt;

&lt;p&gt;Stupid as I feel, I also feel like I gained a lot from the hour I spent on this; I finally got to delve into the Fluent NHibernate code.&lt;/p&gt;&lt;img src="http://statichippo.com/aggbug/52.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/archive/2010/01/20/mapping-serializable-types-using-fluent-nhibernate.aspx</guid>
            <pubDate>Wed, 20 Jan 2010 16:35:25 GMT</pubDate>
            <wfw:comment>http://statichippo.com/comments/52.aspx</wfw:comment>
            <comments>http://statichippo.com/archive/2010/01/20/mapping-serializable-types-using-fluent-nhibernate.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://statichippo.com/comments/commentRss/52.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/services/trackbacks/52.aspx</trackback:ping>
        </item>
        <item>
            <title>NHibernate Generic Dictionary Mapping</title>
            <link>http://statichippo.com/archive/2009/01/14/nhibernate-generic-dictionary-mapping.aspx</link>
            <description>&lt;p&gt;"NHibernate: have I told you today how much I love you?"&lt;/p&gt;  &lt;p&gt;The other day I had a good reason to use a generic dictionary and I though hey, I wonder how I'll get that working with NHibernate...  It's very simple to persist Generic Dictionarys with NHibernate as I found out.  Let's see an example...&lt;/p&gt;  &lt;h2 style="text-align: center"&gt;&lt;strong&gt;.NET PSEUDO CODE&lt;/strong&gt;&lt;/h2&gt;  &lt;p&gt;Take a person and his favorite or least favorite deserts:&lt;/p&gt;  &lt;p&gt;First we have a Person object&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;class Person      &lt;br /&gt;-----------       &lt;br /&gt;int PersonId       &lt;br /&gt;string FirstName       &lt;br /&gt;string LastName&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;And a desert object&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;class Desert      &lt;br /&gt;------------       &lt;br /&gt;int DesertId       &lt;br /&gt;string Name&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now we want to associate a Person with all the deserts and rate how much he likes them (I know, it's contrived, but it's simpler than the business case I did this with yesterday).  So first we might create an enum for storing how one feels about a particular dessert (we'll call it Rating):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;enum Rating      &lt;br /&gt;-----------------------       &lt;br /&gt;Love,       &lt;br /&gt;Like,       &lt;br /&gt;Impartial,       &lt;br /&gt;Dislike,       &lt;br /&gt;Disdain&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;And then we might add a generic dictionary to the Person object like so:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;class Person      &lt;br /&gt;-----------       &lt;br /&gt;string FirstName       &lt;br /&gt;string LastName       &lt;br /&gt;&lt;strong&gt;Dictionary&amp;lt;Desert, Rating&amp;gt; DesertRatings&lt;/strong&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Looks good.  Now how would we use NHibernate to persist this?  First off, let's make a slight change to the Person object because NHibernate actually uses IDictionary, so that last line of the Person object would look more like:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;IDictionary&amp;lt;Desert, Rating&amp;gt; DesertRatings&lt;/strong&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2 style="text-align: center"&gt;&lt;strong&gt;DATABASE TABLES      &lt;br /&gt;&lt;/strong&gt;&lt;/h2&gt;  &lt;p style="text-align: left"&gt;To persist this data we first create the tables in our database.  Assuming we used the code above, I would probably create 3 different tables: 1 to store the Persons, 1 to store Deserts, and 1 to store the association between Persons and their Desert ratings.  The tables might look like this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p style="text-align: left"&gt;&lt;em&gt;PEOPLE&lt;/em&gt;       &lt;br /&gt;PersonId, int       &lt;br /&gt;FirstName, varchar       &lt;br /&gt;LastName, varchar&lt;/p&gt;    &lt;p style="text-align: left"&gt;&lt;em&gt;DESERTS&lt;/em&gt;       &lt;br /&gt;DesertId, int       &lt;br /&gt;Name, varchar&lt;/p&gt;    &lt;p style="text-align: left"&gt;&lt;em&gt;PEOPLEDESERTRATINGS  (PersonId and DesertId will be the primary keys since 1 person can only have 1 rating for a specific desert)&lt;/em&gt;       &lt;br /&gt;PersonId, int       &lt;br /&gt;DesertId, int       &lt;br /&gt;Rating, int (this will store the integer representation of the enum)&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2 style="text-align: center"&gt;&lt;strong&gt;NHibernate Mapping&lt;/strong&gt;s&lt;/h2&gt;  &lt;p&gt;Now behold the magic of NHibernate.  Let's take a look at what the Person.hbm.xml file might look like:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p style="text-align: left"&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;      &lt;br /&gt;&amp;lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MyAssembly" namespace=MyNamespace"&amp;gt;       &lt;br /&gt;&amp;lt;class name="Person" table="People"&amp;gt;       &lt;br /&gt;&amp;lt;id name="PersonId" column="PersonId" type="Int32" unsaved-value="0"&amp;gt;       &lt;br /&gt;&amp;lt;generator class="native"&amp;gt;&amp;lt;/generator&amp;gt;       &lt;br /&gt;&amp;lt;/id&amp;gt;       &lt;br /&gt;&amp;lt;property name="FirstName" column="FirstName" type="String" not-null="true" /&amp;gt;       &lt;br /&gt;&amp;lt;property name="LastName" column="LastName" type="String" not-null="true" /&amp;gt;       &lt;br /&gt;&lt;strong&gt;&amp;lt;map name="DesertRatings" table="PeopleDesertRatings"&amp;gt;        &lt;br /&gt;&amp;lt;key column="PersonId" /&amp;gt;         &lt;br /&gt;&amp;lt;index-many-to-many class="Desert" column="DesertId" /&amp;gt;         &lt;br /&gt;&amp;lt;element column="Rating" type="MyNamespace.Rating" not-null="true" /&amp;gt;         &lt;br /&gt;&amp;lt;/map&amp;gt;&lt;/strong&gt;       &lt;br /&gt;&amp;lt;/class&amp;gt;       &lt;br /&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p style="text-align: left" /&gt;  &lt;p style="text-align: left"&gt;That's all there is too it.  There's a lot that I didn't cover here, and this is NOT meant to be a tutorial on how to design your objects or tables.  However, I think I've shown how amazingly easy it is to persist this kind of thing using NHibernate.  I didn't find anything online about this before I tried it and it worked the first time, but I would have felt more comfortable trying it had I seen someone else do it first.  So hopefully this post helps someone feel comfortable diving right in.&lt;/p&gt;&lt;img src="http://statichippo.com/aggbug/31.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Noah</dc:creator>
            <guid>http://statichippo.com/archive/2009/01/14/nhibernate-generic-dictionary-mapping.aspx</guid>
            <pubDate>Wed, 14 Jan 2009 21:42:00 GMT</pubDate>
            <wfw:comment>http://statichippo.com/comments/31.aspx</wfw:comment>
            <comments>http://statichippo.com/archive/2009/01/14/nhibernate-generic-dictionary-mapping.aspx#feedback</comments>
            <wfw:commentRss>http://statichippo.com/comments/commentRss/31.aspx</wfw:commentRss>
            <trackback:ping>http://statichippo.com/services/trackbacks/31.aspx</trackback:ping>
        </item>
    </channel>
</rss>