Consider the following code:
Code:
Shipment shipment = new Shipment();
EntityTransaction txn = entityManager.getTransaction();
entityManager.persist(shipment);
txn.commit();
entityManager.refresh(shipment);
entityManager.close();
or
Code:
Transaction txn = session.beginTransaction();
Shipment shipment = new Shipment();
session.save(shipment);
session.flush();
txn.commit();
session.refresh(shipment);
session.close();
I noticed that nothing was put into the L2 cache after the commit. However, the refresh() would force a database select, and a CacheEntry will be created in the L2 cache.
Is it true that Hibernate only put into L2 cache after data is fetched from the database and not when a new transient entity is persisted?