Difference Between @JoinColumn and @JoinTable in hibernate

  • @JoinTable stores the id of  both the entity into a separate table wheres @JoinColumn stores id of the another entity in a new column in  same table.
  • Use @JoinColumn when the entities have direct relationship i.e a foreign key between two entity.
  • Use @JoinTable when you manage the relationship between entities in another table.
  • @JoinTable : Use this when  you need a more normalized database. ie. to reduce redundancy.
  • @JoinColumn : Use this for better performance as it does not need to join extra table.

Leave a comment