[英]Nhibernate mapping of Table without Entity
I have a Table And Entity called Software 我有一个称为软件的表和实体
Then I have a Table LinkedSoftware with no Entity 然后我有一个没有实体的表LinkedSoftware
I am struggling to setup my hibernate mapping file, keep getting mapping errors. 我正在努力设置我的休眠映射文件,不断出现映射错误。 I have tried the following with no luck:
我没有运气就尝试了以下方法:
<set name="linkedSoftware" access="field" cascade="all-delete-orphan" table="LinkedSoftware">
<many-to-many class="Software" column="BaseSoftwareId" />
<many-to-many class="Software" column="LinkedSoftwareId" />
</set>
<many-to-one name="LinkedSoftware" column="BaseSoftwareId" cascade="save-update" class="Software" />
<many-to-one name="LinkedSoftware" column="LinkedSoftwareId" cascade="save- update" class="Software" />-->
Is there anyone that can please point me in the right direction. 有没有人能指出我正确的方向。 I tried to google but couldnt really find an answer.
我试图用谷歌搜索,但找不到真正的答案。
I think you should make table LinkedSotware
an entity, too. 我认为您也应该使表
LinkedSotware
成为实体。 Then try write your set
more like this: 然后尝试像这样编写您的
set
:
<set name="LinkedSoftware" table="LinkedSoftware">
<key>
<column name="BaseSoftwareId" />
</key>
<one-to-many class="LinkedSoftware" />
</set>
But not sure if that is everything, because that will give you into set just the LinkedSoftware
instances which have the instance of Software
as BaseSoftware
. 但是不确定是否全部,因为这会使您仅设置
LinkedSoftware
实例,该实例的Software
实例为BaseSoftware
。 Sorry for my English, hope you understand. 对不起,我的英语,希望您能理解。
And then in LinkedSoftware
mapping: 然后在
LinkedSoftware
映射中:
<many-to-one name="BaseSoftware" class="Software">
<column name="BaseSoftwareId" />
</many-to-one>
<many-to-one name="LinkedSoftware" class="Software">
<column name="LinkedSoftwareId" />
</many-to-one>
This NHibernate: Two foreign keys in the same table against same column could help you. NHibernate:在同一表中针对同一列的两个外键可以为您提供帮助。 And I would avoid using many-to-many, I think this would be more flexible.
而且我会避免使用多对多方式,我认为这样会更灵活。 For many-to-many explanation see Nhibernate: How to represent Many-To-Many relationships with One-to-Many relationships?
有关多对多说明,请参见Nhibernate:如何用一对多关系表示多对多关系? .
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.