Customer mapping is defined to get the object loaded lazily.
load_Object_Doesnt_Load_The_Entity
Load the customer.
No object is loaded (from database).
Customer object is not of Customer class instead a auto-generated sub-class domain.Customer_$$_javassist_2.
Load another customer which doesn't exist.
Loaded object is not null.
cannot_Use_Copy_Constructor_With_Lazy_Objects
Load a customer.
Access a method.
Entity loaded from database.
Create a new Customer from this customer.
NullPointerException.
Note: The copy constructor uses the fields from the object which is just a proxy and it doesn't hold the data.
get_Doesnt_Load_Proxy
Get the customer.
Load object class is same as Customer class.
Get a not existing customer.
object is null.
children_List_Is_Lazy
Load a customer which has accounts.
No account is loaded.
Get the account count.
Accounts are loaded.
many_To_One_Entity_Is_Lazy
Load a customer.
Get city from the customer.
No cities are loaded.
City object is of City class (is auto-generated sub-class)
Get name of the city.
City is loaded.
n_Plus_One_Query (LazyLoadingProblem)
Get customer and its accounts without loading transactions. (2 account, each with three transactions).
Load all transactions.
Six transactions loaded.
Two query fired.
no_N_Plus_One_Query
Get customer and its accounts without loading transactions. (2 account, each with three transactions).
Load all transactions.
Six transactions loaded.
One query fired.
Note: In account mapping, define the relationship to account with batch-size=2 (<bag name="transactions" cascade="all-delete-orphan" lazy="true" batch-size="2" inverse="true">). When a transaction is accessed, transactions belonging to other accounts in the session are also loaded. Hibernate uses in query to achieve this (where transactio0_.AccountId in (?, ?)).
n_Plus_One_Query_For_Many_To_One (LazyLoadingProblem)
Load all customers.
Access the city of all of them.
Three cities are loaded.
Three queries are executed.
no_N_Plus_One_Query_For_Many_To_One
Load all customers.
Access the city of all of them.
Three cities are loaded.
Two queries are executed.
Note: In City mapping a batch-size of 2 is specified (<class name="City" table="Cities" lazy="true" batch-size="2">). When cities are accessed for a customer, cities belonging to other customers are also loaded. Since the batch-size is 2 two queries are executed loading 2 and 1 cities in each query. If batch-size is 3, only one query would be executed.
load_Subclass_Doesnt_Return_Subclass_When_Requested_Through_Baseclass
Load a commercial customer (by specifying Customer.class as the type).
Cast the customer to CommercialCustomer.
ClassCastException.