Blog Archives

Inverse Relationship In Hibernate And JPA

Inverse attribute in hibernate defines which side is responsible of the association maintenance. In a one-to-many (bidirectional) or many-to-many relationship the side having inverse=”false” (default value) has this responsibility (and will create the appropriate SQL query – insert, update or delete). Changes made to the association on the side of the inverse=”true” are not persisted in DB.
In Hibernate, only the relationship owner should maintain the relationship, and the “inverse” keyword is created to define which side is the owner to maintain the relationship.

Few good links explaining this concept can be found here, here and here.

Inverse attribute with JPA Annotations

inverse=”true” is an attribute to be specified in the hbm.xml but in JPA it is specified using the mappedBy attribute of an @OneToMany annotation.