Hi,
>From reading the spec and the Pro EJB 3 book, I was under the impression
that a call to em.refresh() would refresh from the database regardless.  No
questions asked.  But, I am finding that we don't work that way.  I made a
simple update to our simple PersistenceTest using the AllFieldTypes
(non-versioned) and NamedEntity (versioned) objects.  And, neither one will
load when refresh() is called.  For some reason, with the AllFieldTypes,
none of the fields are being detected as being updated.  And, with the
NamedEntity, since the version field hasn't been updated, then it doesn't
refresh the rest of the object.

>From my reading, this doesn't sound like proper processing.  But, before I
start making any changes, I'm looking for alternate interpretations of the
spec.  Thanks.

I've attached a patch for PersistenceTest, if you are interested in trying
it out.

Kevin
Index: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
===================================================================
--- openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java   (revision 581589)
+++ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java   (working copy)
@@ -34,7 +34,7 @@
     extends SingleEMFTestCase {
 
     public void setUp() {
-        setUp(AllFieldTypes.class);
+        setUp(AllFieldTypes.class, NamedEntity.class);
     }
 
     public void testCreateEntityManager() {
@@ -62,6 +62,28 @@
         em.close();
     }
 
+    public void testRefresh() {
+        EntityManager em = emf.createEntityManager();
+        AllFieldTypes aft = new AllFieldTypes();  // nonVersioned
+        NamedEntity ne = new NamedEntity();  // Versioned
+        em.getTransaction().begin();
+        em.persist(aft);
+        em.persist(ne);
+        em.getTransaction().commit();
+        
+        assertTrue(em.contains(aft));
+        assertTrue(em.contains(ne));
+        
+        aft.setStringField("updated");
+        ne.setName("updated");
+        em.refresh(aft);
+        em.refresh(ne);
+        
+        assertFalse(ne.getName().equals("updated"));
+        assertFalse(aft.getStringField().equals("updated"));
+        em.close();
+    }
+
     public void testQuery() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();

Reply via email to