I'm got the following mapping:
Code:
<?xml version="1.0" encoding="utf-16"?>
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
<class name="Model.Rule, Model" table="Rules" discriminator-value="0" >
<id name="Id" access="nosetter.camelcase-underscore" column="RuleId" type="Int32" unsaved-value="0">
<generator class="native">
</generator>
</id>
<discriminator column="RuleTypeId" type="String" />
<property name="Severity" access="property" column="Severity" />
<property name="EndDate" access="property" column="EndDate" type="System.DateTime" />
<property name="StartDate" access="property" column="StartDate" type="System.DateTime" />
<any name="Entity" access="property" id-type="Int32" meta-type="Int32" >
<meta-value value="1" class="Model.Board, Model" />
<column name="RuleEntityType" />
<column name="RuleEntityId" />
</any>
<subclass name="Model.Rules.EmployeeRule, Model" discriminator-value="-1">
<property name="_employeeId" access="field" column="RuleParameter1" type="Int32" />
<subclass name="Model.Rules.EmployeeSeperation, Model" discriminator-value="2">
<property name="_secondWorkerId" access="field" column="RuleParameter2" type="Int32" />
</subclass>
</subclass>
<subclass name="Model.NumberOfShifts, Model" discriminator-value="1">
<property name="Period" access="property" column="RuleParameter1Type" />
<property name="ShiftsNumber" access="property" column="RuleParameter1" type="Int32" />
</subclass>
</class>
</hibernate-mapping>
I'm getting this error:
Quote:
TestCase 'Tests.EmployeeScheduleTest.LoadRules' failed: NHibernate.MappingException : Error parsing discriminator value: '2'
----> System.ArgumentException : Item has already been added. Key in dictionary: '2' Key being added: '2'
at NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, Settings settings)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at Castle.ActiveRecord.Framework.SessionFactoryHolder.GetSessionFactory(Type type)
at Castle.ActiveRecord.Framework.SessionFactoryHolder.CreateSession(Type type)
at Castle.ActiveRecord.ActiveRecordBase.Save(Object instance)
at Castle.ActiveRecord.ActiveRecordBase.Save()
E:\ssc\Tests\EmployeeScheduleTest.cs(70,0): at Tests.EmployeeScheduleTest.LoadRules()
--MappingException
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at System.Collections.Hashtable.Add(Object key, Object value)
at NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
I've only one 2 as a discriminator. What is going on?