0

I have an issue with a two subclasses using the same table and same fields. Even though the generated table has this fields as nullable uniqueidentifiers, when I save the one record that does not use the third column, then the created field has a value of "000000000-0000-0000-0000-000000000000" instead of NULL. Other parts of application require this place to be null. Here's the code. What's wrong?

   <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                       assembly=".."
                       namespace="...">
      <class name="TEST" table="..." discriminator-value="not null">
        <id name="Id" column="tID">
          <generator class="assigned" />
        </id>
        <discriminator column="iTestTypeID" type="Int32" not-null="true"/>

        <property name="TotalScore" column="fTotalScore"/>
        <property name="IsTimedOut" column="bTimedOut"/>
    </hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly=".."
                   namespace="...">
  <subclass name="TestA" extends="TEST" discriminator-value="3">
    <many-to-one name="Department" column="uTestCriteria01" cascade="save-update" not-null="false" />
    <many-to-one name="Building" column="uTestCriteria02" cascade="save-update" not-null="false" />
  </subclass>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly=".."
                   namespace="...">
  <subclass name="TestB" extends="TEST" discriminator-value="3">
    <many-to-one name="Building" column="uTestCriteria01" cascade="save-update" not-null="false" />
    <many-to-one name="Floor" column="uTestCriteria02" cascade="save-update" not-null="false" />
    <many-to-one name="Room" column="uTestCriteria03" cascade="save-update" not-null="false" />
  </subclass>
</hibernate-mapping>
jjaskulowski
  • 2,524
  • 3
  • 26
  • 36

1 Answers1

1

My guess would be that your objects aren't using nullable types.

Do you have the types defined like this:

public class A
{
    public Guid? field { get; set; }
}

Take a look at this StackOverflow article for an explanation:
How can I default a parameter to Guid.Empty in C#?

Also in your question I would list the specific field(s) you are talking about so there is no confusion and post the code for your objects that are tied to this mapping.

Community
  • 1
  • 1
Cole W
  • 15,123
  • 6
  • 51
  • 85