From 2675cbef0fe4db90011c2db084d7376a6bed02ad Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Thu, 18 Aug 2016 19:05:38 +0200 Subject: [PATCH] Refactor Lazy/Eager loading examples --- .../hibernate/fetching/view/FetchingAppView.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/spring-hibernate4/src/main/java/com/baeldung/hibernate/fetching/view/FetchingAppView.java b/spring-hibernate4/src/main/java/com/baeldung/hibernate/fetching/view/FetchingAppView.java index 0e4c211bb8..8817bb4809 100644 --- a/spring-hibernate4/src/main/java/com/baeldung/hibernate/fetching/view/FetchingAppView.java +++ b/spring-hibernate4/src/main/java/com/baeldung/hibernate/fetching/view/FetchingAppView.java @@ -21,8 +21,7 @@ public class FetchingAppView { public Set lazyLoaded() { final Session sessionLazy = HibernateUtil.getHibernateSession("lazy"); List users = sessionLazy.createQuery("From UserLazy").list(); - UserLazy userLazyLoaded = new UserLazy(); - userLazyLoaded = users.get(3); + UserLazy userLazyLoaded = users.get(3); // since data is lazyloaded so data won't be initialized return (userLazyLoaded.getOrderDetail()); } @@ -33,8 +32,7 @@ public class FetchingAppView { // data should be loaded in the following line // also note the queries generated List user = sessionEager.createQuery("From UserEager").list(); - UserEager userEagerLoaded = new UserEager(); - userEagerLoaded = user.get(3); + UserEager userEagerLoaded = user.get(3); return userEagerLoaded.getOrderDetail(); } @@ -43,8 +41,7 @@ public class FetchingAppView { public void createTestData() { final Session session = HibernateUtil.getHibernateSession("lazy"); - Transaction tx = null; - tx = session.beginTransaction(); + Transaction tx = session.beginTransaction(); final UserLazy user1 = new UserLazy(); final UserLazy user2 = new UserLazy(); final UserLazy user3 = new UserLazy();