I am a newbie to Java Persistence API and Hibernate.
What is the difference between FetchType.LAZY
and FetchType.EAGER
in Java Persistence API?
I am a newbie to Java Persistence API and Hibernate.
What is the difference between FetchType.LAZY
and FetchType.EAGER
in Java Persistence API?
Book.java
Subject.java
HibernateUtil.java
Main.java
Check the retrieve() method of Main.java. When we get Subject, then its collection listBooks, annotated with
@OneToMany
, will be loaded lazily. But, on the other hand, Books related association of collection subject, annotated with@ManyToOne
, loads eargerly (by[default][1]
for@ManyToOne
,fetchType=EAGER
). We can change the behaviour by placing fetchType.EAGER on@OneToMany
Subject.java or fetchType.LAZY on@ManyToOne
in Books.java.