Hibernate Fetching Update (#607)
* BAEL-212 Contains: 1. Hibernate Criteria Query Classes 2. Hibernate Criteria Query Test * Updating the config file and the HibernateUtil class * Hibernate Criteria Queries Example * Hibernate Fetching : Eager Loading vs Lazy Loading * Hibernate Criteria Query files * Hibernate Eager Loading and Lazy Loading Changes * Latest Changes on Fetching * Fetching Changes * Latest Changes * Latest Changes * Undoing the changes
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
fe16518c17
commit
6c062ca19e
+24
-5
@@ -1,24 +1,43 @@
|
||||
package com.baeldung.hibernate.fetching;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.hibernate.fetching.model.OrderDetail;
|
||||
|
||||
import com.baeldung.hibernate.fetching.view.FetchingAppView;
|
||||
|
||||
public class HibernateFetchingTest {
|
||||
|
||||
|
||||
//this loads sample data in the database
|
||||
@Before
|
||||
public void addFecthingTestData(){
|
||||
FetchingAppView fav = new FetchingAppView();
|
||||
fav.createTestData();
|
||||
}
|
||||
|
||||
//testLazyFetching() tests the lazy loading
|
||||
//Since it lazily loaded so orderDetalSetLazy won't
|
||||
//be initialized
|
||||
@Test
|
||||
public void testLazyFetching() {
|
||||
FetchingAppView fav = new FetchingAppView();
|
||||
fav.createTestData();
|
||||
assertFalse(fav.lazyLoaded());
|
||||
Set<OrderDetail> orderDetalSetLazy = fav.lazyLoaded();
|
||||
assertFalse(Hibernate.isInitialized(orderDetalSetLazy));
|
||||
}
|
||||
|
||||
|
||||
//testEagerFetching() tests the eager loading
|
||||
//Since it eagerly loaded so orderDetalSetLazy would
|
||||
//be initialized
|
||||
@Test
|
||||
public void testEagerFetching() {
|
||||
FetchingAppView fav = new FetchingAppView();
|
||||
assertTrue(fav.eagerLoaded());
|
||||
Set<OrderDetail> orderDetalSetEager = fav.eagerLoaded();
|
||||
assertTrue(Hibernate.isInitialized(orderDetalSetEager));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user