0
// pm is a product manager object which handles actual database calls
Product product = pm.findProduct( 1 );
List<Product> products = pm.findAllProducts();
products.stream().forEach( System.out::println );

pm.update( product ); // pm object delegates by calling merge on an entity manager object
products = pm.findAllProducts();
products.stream().forEach( System.out::println );

Both println statements print same number of records, without any change. As there is no state change in product managed entity,

  1. Will persistence provider(PP) still send it to the database for update? State for both cases: when second-level cache is and is not used.
  2. If no, how does PP determine changes?
  3. If yes, as there's no difference in second output, how do I know for sure that database updated the record? IOW, how can I determine that database had executed an update statement?

EDIT: Added 'derby' tag.

lupchiazoem
  • 8,026
  • 6
  • 36
  • 42

2 Answers2

1

"how can I determine that database had executed an update statement?" You can enable sql logging and look in log which sql queries are executed. How to view the SQL queries issued by JPA?

Spasoje Petronijević
  • 1,476
  • 3
  • 13
  • 27
0
  1. As per logging, persistence provider does not issue an update statement.
  2. This could be JPA implementation specific.
lupchiazoem
  • 8,026
  • 6
  • 36
  • 42