In a relational database in a one-to-many relationship, a row in table X can have  more than one matching row in table Y.

In Object oriented programming, one instance of entity refers to multiple instances of another entity in the  relation called one-to-many relation.

In this tutorial used the relationship between Engineering Branch and Students. In an Engineering college each Branch have many Students.

what is bidirectional?

  • Bidirectional relationship provides navigational access in both directions, so that you can access the other side entity without explicit queries.

one-to-many Tables structure in Database : mapping : mapping :

Cascade :

  • Whenever rows in the parent table manipulated (inserted, updated, deleted) the respective rows of the child table with a matching key column will be manipulated as well. This is called Cascade in Database.
  • JPA translates entity state transitions to database DML statements.

@JoinColumn :

  • @JoinColumn Specifies a column for joining an entity association or element collection. The annotation @JoinColumn indicates that this entity is the owner of the relationship. That is the corresponding table has a column with a foreign key to the referenced table.
To Understand Cascade and @JoinColumn mapping in entity associations see :
Key points to understand associations

mappedBy :

The mappedBy element defines a bidirectional relationship. This attribute allows you to refer the associated entities from both sides.

one-to-many bidirectional association testing :

Console Output :

Download Application – (15 KB)