0

What is the difference between inverse="true" and constrained="true".

Aren't both used to make the association bidirectional? Also aren't both adding a foreign key constraint linking the primary key in the 2 tables?

I am confused. Please guide me.

v.ladynev
  • 19,275
  • 8
  • 46
  • 67
sid
  • 129
  • 3
  • 11

1 Answers1

1

constrained is used for lazy loading of one-to-one relations. Because they are implemented by shared primary keys, NHibernate doesn't know if there is a record in the other table before it fetched it. With constrained you tell NHibernate that there is always a record expected, so it can create a proxy. See this blog post from Ayende Rahien.

With inverse, you tell NHibernate that a one-to-many relation is already stored by the many side, so it doesn't need to store the collection on the one side. I tried to explain it here: When to use inverse=false on NHibernate / Hibernate OneToMany relationships?

Community
  • 1
  • 1
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193