I'm wondering whether or not the JPA EntityManager.persist method is 100% guaranteed to always call the database? Here's a code snippet:
Code:
EntityManager em = emf.createEntityManager();
Product p = new Product();
p.setAmount(1.0);
p.setName("FooBar");
EntityTransaction et = em.getTransaction();
et.begin();
em.persist(p);
// Test with JDBC
Connection c = ((EntityManagerImpl) em).getSession().connection();
System.out.println("AC = " + c.getAutoCommit());
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from products where name = 'FooBar'");
assertTrue(rs.next());
assertEquals("FooBar", rs.getString("name"));
So, this works, but my question is will it always work no matter what? Will em.persist always execute the SQL even if there are no GeneratedValues or it is an update?