forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Eager Loading vs Lazy Loading
- Loading branch information
Grzegorz Piwowarek
committed
Aug 12, 2016
1 parent
e5c5b89
commit 414821e
Showing
6 changed files
with
289 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 20 additions & 23 deletions
43
spring-hibernate4/src/main/java/com/baeldung/hibernate/fetching/util/HibernateUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,30 @@ | ||
package com.baeldung.hibernate.fetching.util; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.cfg.Configuration; | ||
|
||
public class HibernateUtil { | ||
private static SessionFactory factory; | ||
|
||
@SuppressWarnings("deprecation") | ||
public static Session getHibernateSession(String fetchMethod) { | ||
//two config files are there | ||
//one with lazy loading enabled | ||
//another lazy = false | ||
SessionFactory sf = null; | ||
if ("lazy".equals(fetchMethod)) { | ||
sf = new Configuration().configure("fetchingLazy.cfg.xml").buildSessionFactory(); | ||
} else { | ||
sf = new Configuration().configure("fetching.cfg.xml").buildSessionFactory(); | ||
} | ||
// fetching.cfg.xml is used for this example | ||
final Session session = sf.openSession(); | ||
return session; | ||
} | ||
@SuppressWarnings("deprecation") | ||
public static Session getHibernateSession(String fetchMethod) { | ||
//two config files are there | ||
//one with lazy loading enabled | ||
//another lazy = false | ||
|
||
public static Session getHibernateSession() { | ||
SessionFactory sf = null; | ||
sf = new Configuration().configure("fetching.cfg.xml").buildSessionFactory(); | ||
final Session session = sf.openSession(); | ||
return session; | ||
} | ||
final String configFileName = "lazy".equals(fetchMethod) ? | ||
"fetchingLazy.cfg.xml" : | ||
"fetching.cfg.xml"; | ||
|
||
return new Configuration() | ||
.configure(configFileName) | ||
.buildSessionFactory().openSession(); | ||
} | ||
|
||
public static Session getHibernateSession() { | ||
return new Configuration() | ||
.configure("fetching.cfg.xml") | ||
.buildSessionFactory() | ||
.openSession(); | ||
} | ||
|
||
} |
Oops, something went wrong.