1

I checked Hibernate 'Inverse' in mapping file and http://www.nhforge.org/doc/nh/en/#collections-bidirectional and http://blog.xebia.com/2009/03/16/jpa-implementation-patterns-bidirectional-assocations/

Do i always have to use inverse=true for the bidirectional mappings on the set (parent) side?

What are the alternatives? Is it also possible to define both sides not-null and not updateable?

Community
  • 1
  • 1
Koray Güclü
  • 2,857
  • 1
  • 34
  • 30

1 Answers1

1

if you have a bidirectional mapping then it causes harm to not have one side inversed because if you have Cascade.All both sides would try to maintain the association meaning duplicate entries in link tables or redundant Updates.

Both sides as not updateable is useful for readonly associations.

Firo
  • 30,626
  • 4
  • 55
  • 94
  • http://docs.oracle.com/javaee/5/api/javax/persistence/OneToMany.html states for MappedBy that "The field that owns the relationship. **Required** _unless the relationship is unidirectional_. ". That means for bidirectional relations inverse is always required and cascade should be both on two sides right? – Koray Güclü Mar 07 '12 at 15:13
  • "In a bidirectional relationship, one of the sides (and only one) has to be the owner: the owner is responsible for the association column(s) update." REF:http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/ – Koray Güclü Mar 07 '12 at 17:52
  • right the association is a column(or table in manytomany) in the database. – Firo Mar 08 '12 at 10:33
  • This can give more information to other people : http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/example-parentchild.html#example-parentchild-cascades and http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/example-parentchild.html#example-parentchild-bidir – Koray Güclü Mar 08 '12 at 13:45
  • http://www.sleberknight.com/blog/sleberkn/entry/20070329 is also nice about this topic – Koray Güclü Mar 08 '12 at 17:34
  • "Making one side of the association inverse tells Hibernate to consider it a mirror of the other side. That is all that is necessary for Hibernate to resolve any issues that arise when transforming a directional navigation model to a SQL database schema. The rules are straightforward: all bi-directional associations need one side as inverse. In a one-to-many association it has to be the many-side, and in many-to-many association you can select either side." Source:http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html/ch01.html#tutorial-associations-usingbidir – Koray Güclü Sep 11 '12 at 08:51