Issue
I have a userAccount entity mapped with a country entity . The country mapping in UserAccount class is like this
@ManyToOne(fetch=FetchType.EAGER)
@Fetch(FetchMode.JOIN)
@JoinColumn(name="f_country_id", nullable=true, insertable=false, updatable=false)
private Country country;
Even there is fetchmode defined as Join, hibernate fires a separate SQL Select to fetch countries.
Solution
Remove the fetch=FetchType.EAGER
. Eager fetching triggers cascading select statements.
If you are using explicit HQL query e.g. "from User where something = someValue", Hibernate will not respect the annotated Fetch mode. You would need to specify the join in the HQL query or the fetch mode in the criteria.
Answered By - Satadru Biswas
Answer Checked By - David Marino (JavaFixing Volunteer)