What is the meaning of inverseJoinColumns hibernation?

I understand the hibernate @JoinTable annotation, but I don't understand inverseJoinColumns. What is it used for?

eg.

@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinTable(name = "stock_category", catalog = "mkyongdb", joinColumns = { @JoinColumn(name = "STOCK_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "CATEGORY_ID", nullable = false, updatable = false) }) public Set<Category> getCategories() { return this.categories; } 
+6
source share
1 answer

From javadocs, this means:

(Optional) Columns of a foreign key in a join table that reference the main table of an object that does not own the association

In layman's terms, this is the Category column that will be used as part of the JoinTable relationship between the current object and Category .

If you do not specify joinColumns and inverseJoinColumns in the inverseJoinColumns annotation, the persistence provider assumes a primary key for the relationship with the primary key join and still stores the equivalent identity columns for the two related objects in the table by default.

+5
source

All Articles