openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fay Wang <fyw...@yahoo.com>
Subject Re: Refreshing detached entities
Date Thu, 11 Mar 2010 19:20:24 GMT
hi Jerry,
       I could not reproduce this problem and I am using the trunk level code.

11256  callback  TRACE  [main] openjpa.jdbc.SQL - <t 16785420, conn 20448186> executing
prepstmnt 2721032 INSERT INTO EntityA (id) VALUES (?) [params=(int) 1]
11276  callback  TRACE  [main] openjpa.jdbc.SQL - <t 16785420, conn 20448186> [20 ms]
spent
java.lang.IllegalArgumentException: refresh can not be invoked on "callback.EntityA-1". This
entity is either detached or not persistent or null.
    at org.apache.openjpa.persistence.EntityManagerImpl.assertValidAttchedEntity(EntityManagerImpl.java:1344)
    at org.apache.openjpa.persistence.EntityManagerImpl.refresh(EntityManagerImpl.java:744)
    at org.apache.openjpa.persistence.EntityManagerImpl.refresh(EntityManagerImpl.java:731)
    at callback.TestCallback.testRefreshOnDetachedEntity(TestCallback.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(Unknown Source)
    at junit.framework.TestCase.runBare(Unknown Source)
    at junit.framework.TestResult$1.protect(Unknown Source)
    at junit.framework.TestResult.runProtected(Unknown Source)SUCCESS: Refresh detached

Here is my test code snippet:
    public void testRefreshOnDetachedEntity() { 
        try {
            EntityManager em = emf.createEntityManager();
            em.getTransaction().begin();
            EntityA a = new EntityA();
            a.setId(2);
            em.persist(a);
            em.flush();
            em.detach(a);
            em.refresh(a);
            System.err.println("ERROR: No exception from em.refresh(detached)");
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            System.out.println("SUCCESS: Refresh detached");
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("ERROR: Unexpected exception from em.refresh(detached): " +
e.toString());
        }            
    }





----- Original Message ----
From: Jerry Carter <jerry@jerrycarter.org>
To: users@openjpa.apache.org
Sent: Thu, March 11, 2010 9:21:13 AM
Subject: Refreshing detached entities


Possible gap in my understanding, but I would expect an exception in this case based on section
3.2.5 of the JPA 2.0 specification: "If [entity] X is new, detached, or removed entity, the
IllegalArgumentException is thrown".

try {
    TestEntity refreshDetached = new TestEntity("refresh detached");
    em.persist(refreshDetached);
    em.flush();
    em.detach(refreshDetached);
    em.refresh(refreshDetached);
    logger.error("ERROR: No exception from em.refresh(detached)");
} catch (IllegalArgumentException e) {
    logger.info("SUCCESS: Refresh detached");
} catch (Exception e) {
    logger.error("ERROR: Unexpected exception from em.refresh(detached): " + e.toString());
}

ERROR: No exception from em.refresh(detached)


      


Mime
View raw message