0

I have a Table And Entity called Software


Software

  • Id
  • Serial
  • Name
  • LinkedSoftware (This field is in the Entity)

Then I have a Table LinkedSoftware with no Entity


LinkedSofware

  • BaseSoftwareId (Relationship with Software.Id)
  • LinkedSoftwareId (Relationship with Software.Id)

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.

user1702369
  • 1,089
  • 2
  • 13
  • 31

1 Answers1

1

I think you should make table LinkedSotware an entity, too. Then try write your set more like this:

 <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. Sorry for my English, hope you understand.

And then in LinkedSoftware mapping:

<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. 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? .

Community
  • 1
  • 1
Margarit
  • 107
  • 9