Nisha_Roy
Nisha_Roy

Reputation: 524

NHibernate Entity mapping

I have an object MainObject which is related to around 20 other objects. These 20 other objects - RelatedObject1, RelatedObject2, etc. The relationship with the MainObject is defined as follows.

1 instance MainObject - > N instances of RelatedObject_1 1 instance MainObject - > N instances of RelatedObject_2 1 instance MainObject - > N instances of RelatedObject_3 . . . 1 instance MainObject -> N instances of RelatedObject_20.

Now all the relationship here is "HAS - A" relationship and not a "IS-A" relationship. It is not a parent-child relationship.

The RelatedObjects have their independent transactional functional flow in the system. Now should I create Bags/Sets/Lists/ for these 20 related Objects in my MainObject.hbm.xml. for accessing their data from the MainObject.

If I create a bag/set/list - I want to ensure that data is not Saved/Persisted in Database when I Save or Update the MainObject. Using which property makes sense in this scenario.

Upvotes: 0

Views: 181

Answers (1)

Firo
Firo

Reputation: 30813

use

  • bag when unordered and possibly duplicates
  • set when unordered and no duplicates
  • list when ordered and possibly duplicates

and set cascade="none" to prevent cascading any operation (save, update, ...)

Upvotes: 1

Related Questions