Monday 19 February 2018

Best way to use @OneToOne in Hibernate

Creating a proper hibernate entity relationship design is one of the difficult task of projects. There are multiple factors that you need to consider while making relationships in entities. You must have proper domain or business knowledge of your project to perform these tasks.

Below factors affects the execution of relationship :
  • Object Fetching strategies
  • Lazy-Eager fetching
  • Performance tuning
  • Making the right table as Owner of relationship
  • Unidirectional or Bidirectional relationship

You need to consider all these factors while creating hibernate entity relationships.

In this blog I will be talking about @OneToOne mapping in Hibernate. I will be explaining two different examples of @OneToOne to understand its lazy feature.

Case 1 : Worker - WorkerProfile relation
Case 2 : Manager - ManagerProfile relation