What are the association annotations for the fetch types in Hibernate?
- User
What are the association annotations for the fetch types in Hibernate?
- Assistant
In Hibernate, the association annotations for fetch types are:
-
@ManyToOne: By default, it uses FetchType.EAGER, which means that the associated entity is loaded immediately when the owning entity is loaded. However, it can be changed to FetchType.LAZY, where the associated entity is loaded only when it is accessed.
-
@OneToMany: By default, it uses FetchType.LAZY, which means that the associated entities are loaded only when they are accessed. However, it can be changed to FetchType.EAGER, where the associated entities are loaded immediately when the owning entity is loaded.
-
@OneToOne: By default, it uses FetchType.EAGER, which means that the associated entity is loaded immediately when the owning entity is loaded. However, it can be changed to FetchType.LAZY, where the associated entity is loaded only when it is accessed.
-
@ManyToMany: By default, it uses FetchType.LAZY, which means that the associated entities are loaded only when they are accessed. However, it can be changed to FetchType.EAGER, where the associated entities are loaded immediately when the owning entity is loaded.
-