educative.io

Confusion between joinTable and inverseJoinTable

The statement from the lesson:
" 6. joinColumns attribute specifies the column(s) in the owner table that becomes a foreign key in the join table. inverseJoinColumns attribute specifies the foreign key column(s) from the inverse side."

My understanding is:
Category entity is the owning entity
Tournament entity is the inverse (child) entity

My understanding is according to the article itself, from this statement:
“So, Category becomes the owning/parent side and Tournament becomes the referenced/ child side.”

But the code, contradicts the above statement and my understanding.
This is the code
joinColumns= @JoinColumn(name =“tournament_id”), //FK of the owning side
inverseJoinColumns=@JoinColumn(name=“category_id”) //FK of inverse side

So what is it? who is the owning side and inverse side ?

Hi @Atul !!
In the code snippet:

joinColumns = @JoinColumn(name = "tournament_id"), // FK of the owning side
inverseJoinColumns = @JoinColumn(name = "category_id") // FK of the inverse side

The joinColumns attribute specifies the foreign key column(s) from the owning side (Category entity in this case) that becomes a part of the join table. The inverseJoinColumns attribute specifies the foreign key column(s) from the inverse side (Tournament entity in this case) that become a part of the join table.

Based on this code snippet, the Tournament entity is the owning side and the Category entity is the inverse side. This means that the Tournament entity is responsible for the foreign key relationship in the join table.
I hope it helps. Happy Learning :blush:

Hi Javeria,

If thats the case, you need to make changes to the article.

Because the article says that category is the owning side and tournament is the inverse side. But code says opposite.

I understand that in many to many relationship, it doesnt matter who is owning and who is inverse. But the article needs to be consistent with whats written and what is actually coded.

Thanks
Atul

1 Like