我尝试添加<discriminator>
:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="X" namespace="X.y">
<class name="RawAttachment" table="Metadata_Attachment">
<id name="AttachmentId">
<generator class="guid" />
</id>
<discriminator column="PAYMENT_TYPE" type="String"/>
<subclass
name="Attachment"
discriminator-value="Cash">
<property name="LocationId"/>
</subclass>
但出现以下错误:
命名空间'urn:nhibernate-mapping-2.2'中的元素'class'具有 命名空间中无效的子元素'discriminator' '瓮:NHibernate的映射-2.2'。预期的可能元素列表: '属性,多对一,一对一,组件,动态组件, 属性,任何,地图,集,列表,包,idbag,数组,原始数组, join,subclass,joined-subclass,union-subclass,loader,sql-insert, sql-update,sql-delete,filter,resultset,query,sql-query'in namespace'urn:nhibernate-mapping-2.2'。
为什么?
答案 0 :(得分:0)
我没有足够的有关您的模型和映射的信息,但似乎是错误的。您应该为每个子类定义一个映射,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="X"
namespace="X">
<class name="RawAttachment">
<id name="AttachmentId">
<generator class="guid.comb" />
</id>
<discriminator column="PAYMENT_TYPE" />
<property name="Prop1" />
<property name="Prop2" not-null="true" />
</class>
</hibernate-mapping>
RawAttachment的子类
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="X"
namespace="X">
<subclass name="RawAttachmentSub" extends="RawAttachment">
<property name="OtherProp"/>
<property name="OtherProp2"/>
</subclass>
</hibernate-mapping>
让我知道它是否有效。
答案 1 :(得分:0)
找到答案:将标签直接移动到标签下方和任何标签之前。
https://forum.hibernate.org/viewtopic.php?p=2368742&sid=3af1d42a54dc239c8287f2bcec2d1412