Hello,
The following code throws an exception when invoking "em.refresh(p)":
1: EntityManager em = emf.createEntityManager();
2: em.getTransaction().begin();
3:
4: Product p = new Product("J&D", 35.0,"Whisky");
5: em.persist(p);
6:
7: em.refresh(p);
8: em.getTransaction().commit();
9: em.close();
When debugging the code, we see that Hibernate didn't write the record into the DB at line 6. He does is like foreseen - when it's required, not earlier.
At line 7, we get the following exception: Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: this instance does not yet exist as a row in the database
When we force Hibernate to flush the record into the DB at line 6, the INSERT is executed and no error occurs. We can do this by executing a select or just force the flush (with all consequences):
6 : em.createQuery("select p from Product p").getResultList();
6 : em.flush();
My question: should the method "refresh" not force Hibernate to write the record into the DB, as does the select or the flush statement wehn placesd before? (Might this be a bug?).
Thanks in advance for your answers.
Pierre