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() {
|
||||
final Session sessionLazy = HibernateUtil.getHibernateSession("lazy");
|
||||
List<UserLazy> 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<UserEager> 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();
|
||||
|
|
Loading…
Reference in New Issue