Refactor Lazy/Eager loading examples
This commit is contained in:
parent
6973039ea9
commit
2675cbef0f
|
@ -21,8 +21,7 @@ public class FetchingAppView {
|
||||||
public Set<OrderDetail> lazyLoaded() {
|
public Set<OrderDetail> lazyLoaded() {
|
||||||
final Session sessionLazy = HibernateUtil.getHibernateSession("lazy");
|
final Session sessionLazy = HibernateUtil.getHibernateSession("lazy");
|
||||||
List<UserLazy> users = sessionLazy.createQuery("From UserLazy").list();
|
List<UserLazy> users = sessionLazy.createQuery("From UserLazy").list();
|
||||||
UserLazy userLazyLoaded = new UserLazy();
|
UserLazy userLazyLoaded = users.get(3);
|
||||||
userLazyLoaded = users.get(3);
|
|
||||||
// since data is lazyloaded so data won't be initialized
|
// since data is lazyloaded so data won't be initialized
|
||||||
return (userLazyLoaded.getOrderDetail());
|
return (userLazyLoaded.getOrderDetail());
|
||||||
}
|
}
|
||||||
|
@ -33,8 +32,7 @@ public class FetchingAppView {
|
||||||
// data should be loaded in the following line
|
// data should be loaded in the following line
|
||||||
// also note the queries generated
|
// also note the queries generated
|
||||||
List<UserEager> user = sessionEager.createQuery("From UserEager").list();
|
List<UserEager> user = sessionEager.createQuery("From UserEager").list();
|
||||||
UserEager userEagerLoaded = new UserEager();
|
UserEager userEagerLoaded = user.get(3);
|
||||||
userEagerLoaded = user.get(3);
|
|
||||||
return userEagerLoaded.getOrderDetail();
|
return userEagerLoaded.getOrderDetail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +41,7 @@ public class FetchingAppView {
|
||||||
public void createTestData() {
|
public void createTestData() {
|
||||||
|
|
||||||
final Session session = HibernateUtil.getHibernateSession("lazy");
|
final Session session = HibernateUtil.getHibernateSession("lazy");
|
||||||
Transaction tx = null;
|
Transaction tx = session.beginTransaction();
|
||||||
tx = session.beginTransaction();
|
|
||||||
final UserLazy user1 = new UserLazy();
|
final UserLazy user1 = new UserLazy();
|
||||||
final UserLazy user2 = new UserLazy();
|
final UserLazy user2 = new UserLazy();
|
||||||
final UserLazy user3 = new UserLazy();
|
final UserLazy user3 = new UserLazy();
|
||||||
|
|
Loading…
Reference in New Issue