Does hibernate automatically create an internal table for maintaining onetomany/manytoone relationship?

Hi ,

I have two tables one is customer the other is orders,
onetomany: customer -> orders
manytoone: orders -> customer
I have seen an internal table created, which is customer_orders.
Does hibernate create it?
How to enable/disable this feature?



Having the mappings you are using for these relations would help.

Did you define the mappedBy attribute properly in your @OneToMany?

Hello! In my designs, I have not used the OneToMany interface, or ManyToMany.
Use only 1-to-1 and N-to-1. And everything works just fine.

JoinColumn(name = "BemPatrimonial_id")
private BemPatrimonial bemPatrimonial;

As explained in the Hibernate User Guide, the following associations match the one-to-many database table relationship:

  • bidirectional @OneToMany
  • unidirectional @ManyToOne and
  • the unidirectional @OneToMany association + @JoinTable

The unidirectional @OneToMany association without @JoinTable looks more like a many-to-many relationship + a Unique Constraint. Only this association uses a separate table.

For more details, check out this article as well.