Why You Should Avoid Unidirectional @OneToMany And Prefer Bidirectional @OneToMany Relationship
Description: As a rule of thumb, unidirectional @OneToMany association is less efficient than the bidirectional @OneToMany or the unidirectional @ManyToOne associations. This application is a sample that exposes the DML statements generated for reads, writes and removal operations when the unidirectional @OneToMany mapping is used.
Key points:
- regular unidirectional
@OneToManyis less efficient than bidirectional@OneToManyassociation - using
@OrderColumncome with some optimizations for removal operations but is still less efficient than bidirectional@OneToManyassociation - using
@JoinColumneliminates the junction table but is still less efficient than bidirectional@OneToManyassociation - using
Setinstead ofListor bidirectional@OneToManywith@JoinColumnrelationship (e.g.,@ManyToOne @JoinColumn(name = "author_id", updatable = false, insertable = false)) still performs worse than bidirectional@OneToManyassociation

