java slow query after multiple call code example

Example 1: 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 ?

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();

Example 2: 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 ?

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