Great question! Hibernate is a very handy framework for removing your need to fully understand SQL, but it will force you to understand things such as¬†joins.
Joining two tables in SQL is the foundation of a relational database, as joins allow you to actually define relationships between tables (objects).
Having said that,¬†relationships¬†are important to understand when talking about fetch types in Hibernate. This is the case because whenever you define a relationship in Hibernate, you‚Äôll also need to define the fetch type. The fetch type essentially decides whether or not to load all of the relationships of a particular object/table as soon as the object/table is initially fetched.
An example of this would be as follows, consider this¬†User¬†object:
view plaincopy to clipboardprint?
Can you spot the relationship in this¬†User¬†object?
If you can‚Äôt, no worries, there‚Äôs an easy way to spot it!
Any time you see a¬†@OneToOne,¬†@OneToMany¬†or¬†@ManyToMany¬†annotations, you‚Äôve got a relationship. What‚Äôs important to note is that the fetch type should be specified within those annotations, if you don‚Äôt specify one then it defaults to¬†FetchType.LAZY.
What this means is that when you load up an instance of the¬†User¬†class via a Hibernate query, Hibernate will NOT load this User‚Äôs¬†Profile¬†unless you explicitly ask it to. So this means that if you try to call¬†user.getUserProfile(), you‚Äôll get a¬†NULL.