Check out example codes for "Let say your Project Manager tell you that your database requests are consume a lot of memory, you need to do something to improve the performance. How would you do it in hibernate ?". It will help you in understanding the concepts better.

Code Example 1

CriteriaBuilder cb = this.em.getCriteriaBuilder();
   
// create update
CriteriaUpdate<Order> update = cb.createCriteriaUpdate(Order.class);
 
// set the root class
Root e = update.from(Order.class);
 
// set update and where clause
update.set("amount", newAmount);
update.where(cb.greaterThanOrEqualTo(e.get("amount"), oldAmount));
 
// perform update
this.em.createQuery(update).executeUpdate();

Code Example 2

2015-03-03 20:28:52,484 DEBUG [org.hibernate.stat.internal.ConcurrentStatisticsImpl] (default task-1) HHH000117: HQL: Select p From Product p, time: 0ms, rows: 10
2015-03-03 20:28:52,484 INFO  [org.hibernate.engine.internal.StatisticalLoggingSessionEventListener] (default task-1) Session Metrics {
    8728028 nanoseconds spent acquiring 12 JDBC connections;
    295527 nanoseconds spent releasing 12 JDBC connections;
    12014439 nanoseconds spent preparing 21 JDBC statements;
    5622686 nanoseconds spent executing 21 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    403863 nanoseconds spent executing 1 flushes (flushing a total of 10 entities and 0 collections);
    25529864 nanoseconds spent executing 1 partial-flushes (flushing a total of 10 entities and 10 collections)
}

Code Example 3

@ManyToMany( mappedBy="authors", fetch=FetchType.LAZY)

Learn ReactJs, React Native from akashmittal.com