Sobes.tech
Junior — Middle

In ORM with a ManyToMany relationship, will the dependent table be automatically loaded when displaying related data if a certain fetch type is set?

sobes.tech AI

Answer from AI

When using a ManyToMany relationship in ORM, loading the dependent table depends on the fetch type set for this relationship. If the fetch type is set to EAGER, the related data will be loaded automatically along with the main object. If it is set to LAZY, the dependent table will not be loaded immediately, but only when explicitly accessed.

Example in Java with JPA:

@ManyToMany(fetch = FetchType.EAGER)
private Set<Role> roles;

In this case, when loading a user, all related roles will be automatically loaded.

In ORM with a ManyToMany relationship, will the… - sobes.tech