我有以下课程。如何为MainBranch.Id列编写映射文档。我在数据库中没有分支表,只想将branchId用于MAINBRANCHCODE。任何的想法?
public class Bundle
{
public virtual Decimal Id { get; set; }
public virtual BundleEntranceInformation Information { get; set; }
}
public class BundleEntranceInformation
{
public virtual Branch MainBranch { get; set; }
}
public class Branch
{
public virtual short Id { get; set; }
}
我的地图文档:
<class name="PromissoryNotes.Server.Data.Bundle, PromissoryNotes.Server.Data" table="BUNDLE" lazy="true">
<id name="Id" column="ID" type="Decimal">
<generator class="increment" />
</id>
<property name="Information.MainBranch.Id" column="MAINBRANCHCODE" type="short"></property>
</class>
答案 0 :(得分:2)
使用组件映射
<class name="BundleEntranceInformation">
<component name="MainBranch">
<property name="Id" column="MAINBRANCHCODE"/>
</component>
</class>
答案 1 :(得分:1)
以下是答案:)
<component name="Information">
<component name="MainBranch">
<property name="Id" column="MAINBRANCHCODE"/>
</component>
</component >
答案 2 :(得分:1)
public class MainClass
{
public virtual long MainKey {get; set;}
public virtual SubClass SubInstance {get; set;}
public class SubClass
{
public virtual long SubKey {get;set;}
}
}
可以映射为:
<class name="MainClass" table="Main">
<id name="MainKey" column="MainId" type="Int64">
<generator class="identity" />
</id>
<many-to-one name="SubInstance" class="MainClass+SubClass" Column="SubId"/>
</class>
<class name="MainClass+SubClass" table="Sub">
<id name="SubKey" column="SubId" type="Int64">
<generator class="identity" />
</id>
</class>
所以加号是关键 (我相信java-hibernate使用美元符号$)