-->
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.  [ 1 post ] 
Author Message
 Post subject: discriminator problem in NHibernate.Mapping.Attributes
PostPosted: Mon Jun 12, 2006 9:57 am 
Newbie

Joined: Sat Sep 03, 2005 4:10 am
Posts: 9
i'm not sure if i'm doing something wrong (i suspect so) but i cannot get the discriminator tag to reliably appear if i generate the hbm xml from NHibernate.Mapping.Attributes.

if i do:

Code:
using System;
using System.Collections.Generic;
using System.Text;

using System.Xml;
using System.Xml.Serialization;

using NHMA = NHibernate.Mapping.Attributes;

namespace ConsoleApplication1
{
    public class Class0
    {
        [NHMA.Id(Name = "Id", TypeType = typeof(int))]
        [NHMA.Generator(1, Class = "native")]
        public int Id;
    }

    public class Class1 : Class0
    {
        [NHMA.Property()]
        public string field;
    }

    [NHMA.Class()]
    public class Class2 : Class1
    {
        [NHMA.Discriminator()]

        [NHMA.Property(Length = 3)]
        public string Field1;
    }

    public class Base
    {
        [XmlIgnore()]
        [NHMA.Id(Name = "Id", TypeType = typeof(int))]
        [NHMA.Generator(1, Class = "native")]

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

        #region private fields
        private int id;
        #endregion
    }

    public class StaticBase : Base
    {
        #region properties
        [NHMA.Property(Length = 3)]
        public string Code
        {
            get { return code; }
            set { code = value; }
        }

        #endregion
        #region private fields
        private string code;
        #endregion
    }

    [NHMA.Class()]
    public class StaticDescription : StaticBase
    {
        #region properties

        [NHMA.Discriminator(Column="class")]

        [NHMA.Property(Length = 50)]
        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        #endregion
        #region private fields
        private string description;
        #endregion
    }

    [NHMA.Subclass(DiscriminatorValue = "NA", ExtendsType = typeof(StaticDescription))]
    public class Nationality : StaticDescription
    {
    }

    class Program
    {
        static void Main(string[] args)
        {
            System.IO.Stream stream = System.IO.File.Create("c:\\test.xml");

            NHMA.HbmSerializer.Default.Validate = true;

            NHMA.HbmSerializer.Default.Serialize(
                stream, System.Reflection.Assembly.GetAssembly(typeof(StaticDescription)));

            stream.Position = 0; // Rewind

            stream.Close();
        }
    }
}


i get

Code:
<?xml version="1.0" encoding="utf-8"?>
<!--Generated from NHibernate.Mapping.Attributes on 2006-06-12 14:37:44Z.-->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="ConsoleApplication1.Class2, ConsoleApplication1">
    <id name="Id" type="Int32">
      <generator class="native" />
    </id>
    <discriminator />
    <property name="Field1" length="3" />
    <property name="field" />
  </class>
  <class name="ConsoleApplication1.StaticDescription, ConsoleApplication1">
    <id name="Id" type="Int32">
      <generator class="native" />
    </id>
    <discriminator column="class" />
    <property name="Description" length="50" />
    <property name="Code" length="3" />
  </class>
  <subclass name="ConsoleApplication1.Nationality, ConsoleApplication1" extends="ConsoleApplication1.StaticDescription, ConsoleApplication1" discriminator-value="NA" />
</hibernate-mapping>


as expected.

however, if i remove classes Class0, Class1 and Class2, not only does Class2 vanish from the hbm xml, the discriminator tag in StaticDescription also goes.

can anyone shed some light on this?

thanks,
mike


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

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.