You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by jr...@apache.org on 2012/05/08 21:46:23 UTC

svn commit: r1335720 [3/5] - in /openjpa/branches/2.2.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-jdbc/sr...

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Certification.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Certification.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Certification.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Certification.java Tue May  8 19:46:20 2012
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Embeddable;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Embeddable
+public class Certification  implements Serializable, Comparable<Certification> {
+
+    private static final long serialVersionUID = 4989402309885734073L;
+
+    private String name;
+    
+    private String level;
+    
+    @Temporal(TemporalType.DATE)
+    private Date certDate;
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setLevel(String level) {
+        this.level = level;
+    }
+
+    public String getLevel() {
+        return level;
+    }
+
+    public void setCertDate(Date certDate) {
+        this.certDate = certDate;
+    }
+
+    public Date getCertDate() {
+        return certDate;
+    }
+
+    @Override
+    public int compareTo(Certification o) {
+        String nameLevelDate = name+level+certDate;
+        String nameLevelDate2 = o.getName()+o.getLevel()+o.getCertDate();
+        return nameLevelDate.compareTo(nameLevelDate2);
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Certification.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/DelayedProxyCollectionsTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/DelayedProxyCollectionsTestCase.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/DelayedProxyCollectionsTestCase.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/DelayedProxyCollectionsTestCase.java Tue May  8 19:46:20 2012
@@ -0,0 +1,810 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.kernel.DetachedStateManager;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+import org.apache.openjpa.util.DelayedProxy;
+import org.apache.openjpa.util.Proxy;
+import org.apache.openjpa.util.ProxyCollection;
+
+/**
+ * Verifies generic delay-load capabilities for delay-load collection proxies.
+ */
+public abstract class DelayedProxyCollectionsTestCase extends SQLListenerTestCase {
+    
+    protected static Set<String> _ignoreMethods;
+    protected static Set<String> _delayMethods;
+    protected static Set<Class<?>> _ignoreInterfaces;
+    
+    public void setUp(Object...props) {
+        List<Object> parms = new ArrayList<Object>();
+        parms.addAll(Arrays.asList(
+                CLEAR_TABLES,
+                "openjpa.ProxyManager", "delayCollectionLoading=true",
+                Award.class, 
+                Location.class,
+                Product.class,
+                Certification.class));
+        parms.addAll(Arrays.asList(props));
+        super.setUp(parms.toArray());
+    }
+    
+    public abstract IAccount createAccount(String name, IUserIdentity ui);
+    public abstract IDepartment createDepartment();
+    public abstract IDepartment findDepartment(EntityManager em, int id);
+    public abstract IEmployee createEmployee();
+    public abstract Collection<IEmployee> createEmployees();
+    public abstract IMember createMember(String name);
+    public abstract IUserIdentity findUserIdentity(EntityManager em, int id);
+    public abstract IUserIdentity createUserIdentity();
+    public abstract Collection<Product> createProducts();
+    public abstract Collection<Certification> createCertifications();
+    public abstract IEmployee getEmployee(Collection<IEmployee> emps, int idx);
+    public abstract Collection<Award> createAwards();
+    public abstract Product getProduct(Collection<Product> products, int idx);
+    public abstract Collection<Location> createLocations();
+    public abstract Collection<IAccount> createAccounts();
+
+    static {
+        // non-indexed delay-capable methods
+        _delayMethods = new HashSet<String>();
+        // generic collection
+        _delayMethods.add(stringMethodName("add", new Class<?>[] {Object.class}));
+        _delayMethods.add(stringMethodName("remove", new Class<?>[] {Object.class}));
+        _delayMethods.add(stringMethodName("removeAll", new Class<?>[] {Collection.class}));
+        _delayMethods.add(stringMethodName("addAll", new Class<?>[] {Collection.class}));
+        // queue
+        _delayMethods.add(stringMethodName("offer", new Class<?>[] {Object.class}));
+        // vector
+        _delayMethods.add(stringMethodName("addElement", new Class<?>[] {Object.class}));
+        _delayMethods.add(stringMethodName("removeElement", new Class<?>[] {Object.class}));
+
+        // non-trigger methods
+        _ignoreMethods = new HashSet<String>();
+        _ignoreMethods.add(stringMethodName("trimToSize", null));
+        _ignoreMethods.add(stringMethodName("ensureCapacity", new Class<?>[] {int.class}));
+        _ignoreMethods.add(stringMethodName("comparator", null));
+        
+        // non-trigger base Object methods
+        _ignoreMethods.add(stringMethodName("wait", new Class<?>[] {long.class}));
+        _ignoreMethods.add(stringMethodName("wait", null));
+        _ignoreMethods.add(stringMethodName("wait", new Class<?>[] {long.class, int.class}));
+        _ignoreMethods.add(stringMethodName("getClass", null));
+        _ignoreMethods.add(stringMethodName("notify", null));
+        _ignoreMethods.add(stringMethodName("notifyAll", null));
+                
+        _ignoreInterfaces = new HashSet<Class<?>>();
+        _ignoreInterfaces.add(DelayedProxy.class);
+        _ignoreInterfaces.add(Proxy.class);
+        _ignoreInterfaces.add(ProxyCollection.class);
+    }
+
+    public static String stringMethodName(Method m) {
+        return stringMethodName(m.getName(), m.getParameterTypes());
+    }
+
+    public static String stringMethodName(String m, Class<?>[] types) {
+        StringBuilder sb = new StringBuilder(m);
+        if (types != null) {
+            for (Class<?> type : types) {
+                sb.append(":");
+                sb.append(type.getName());
+            }
+        }
+        return sb.toString();
+    }
+    
+    public Set<String> methodsToIgnore() {
+        return _ignoreMethods;
+    }
+
+    public Award createAward() {
+        Award a = new Award();
+        a.setAwdName("Employee of the Month " + new Random().nextInt(999999));
+        a.setAwdType("Certificate");
+        return a;
+    }
+
+    public Certification createCertification() {
+        Certification c = new Certification();
+        c.setName("Certification XYZ " + new Random().nextInt(999999));
+        c.setCertDate(new Date());
+        return c;
+    }
+
+    public Product createProduct() {
+        Product p = new Product();
+        p.setName("Product : " + new Random().nextInt(999999));
+        return p;
+    }
+
+    public Location createLocation() {
+        Location l = new Location();
+        l.setAddress(new Random().nextInt(9999) + " Wandering Way");
+        l.setCity("Somewhere");
+        l.setZip(Integer.toString(new Random().nextInt(99999)));
+        return l;
+    }
+    
+    /*
+     * Verify an element can be non-index removed from a delayed proxy collection
+     * without triggering a load of the collection.
+     */
+    public void testSingleRemove() {
+        
+        EntityManager em = emf.createEntityManager();
+        
+        // Create a new department and an employee
+        IDepartment d = createDepartment();
+        IEmployee e = createEmployee();
+        e.setDept(d);
+        e.setEmpName("John");
+        IEmployee e2 = createEmployee();
+        e2.setDept(d);
+        e2.setEmpName("Joe");
+        Collection<IEmployee> emps = createEmployees();
+        emps.add(e);
+        emps.add(e2);
+        d.setEmployees(emps);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        em.clear();
+        
+        resetSQL();
+        d = findDepartment(em, d.getId());
+        // assert the select did not contain the employee table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        assertNotNull(d);
+        emps = d.getEmployees();
+        // assert there was no select
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        assertTrue(emps instanceof DelayedProxy);
+        DelayedProxy dep = (DelayedProxy)emps;
+        dep.setDirectAccess(true);
+        assertEquals(0, emps.size());
+        dep.setDirectAccess(false);
+        assertNotNull(emps);
+
+        // remove the employee from the collection
+        resetSQL();
+        em.getTransaction().begin();
+        emps.remove(e);
+        em.getTransaction().commit();
+        // assert the delete from the join table
+        assertAnySQLAnyOrder("DELETE FROM DC_DEP_EMP .*");
+        // assert no select from employee or dept table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*", "SELECT .* DC_DEPARTMENT .*");
+        
+        // iterate the collection and assert a select from the employee table
+        // and that the expected entity is returned
+        resetSQL();
+        assertEquals(1, emps.size());
+        assertAnySQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        IEmployee e3 = getEmployee(emps, 0);
+        assertEquals(e2, e3);
+        em.close();
+    }
+
+    /*
+     * Verify an element can be non-index added to a delayed proxy collection
+     * without triggering a load on the collection.
+     */
+    public void testSingleAdd() {
+        EntityManager em = emf.createEntityManager();
+        
+        // Create a new department and an employee
+        IDepartment d = createDepartment();
+        IEmployee e = createEmployee();
+        e.setDept(d);
+        e.setEmpName("John");
+        Collection<IEmployee> emps = createEmployees();
+        emps.add(e);
+        d.setEmployees(emps);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        em.clear();
+        
+        resetSQL();
+        d = findDepartment(em, d.getId());
+        // assert the select did not contain the employee table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        assertNotNull(d);
+        emps = d.getEmployees();
+        // assert there was no select
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        assertTrue(emps instanceof DelayedProxy);
+        DelayedProxy dep = (DelayedProxy)emps;
+        dep.setDirectAccess(true);
+        assertEquals(0, emps.size());
+        dep.setDirectAccess(false);
+        assertNotNull(emps);
+
+        // add an employee to the collection
+        resetSQL();
+        em.getTransaction().begin();
+        IEmployee e2 = createEmployee();
+        e2.setDept(d);
+        e2.setEmpName("Joe");
+        emps.add(e2);
+        em.getTransaction().commit();
+        // assert the insert into the employee and join table
+        assertAnySQLAnyOrder("INSERT INTO DC_DEP_EMP .*");
+        assertAnySQLAnyOrder("INSERT INTO DC_EMPLOYEE .*");
+        // assert no select from employee or dept table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*", "SELECT .* DC_DEPARTMENT .*");
+        
+        // call contains and assert a select from the employee table
+        // occurred that the expected entities are returned.
+        resetSQL();
+        assertTrue(emps.contains(e));
+        assertTrue(emps.contains(e2));
+        assertAnySQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        resetSQL();
+        assertEquals(2, emps.size());
+        // verify a second SQL was not issued to get the size
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        em.close();
+    }
+    
+    /*
+     * Verify a mix of non-indexed add and remove operations can occur without
+     * triggering a load on a delayed collection. 
+     */
+    public void testMixedAddRemove() {
+        EntityManager em = emf.createEntityManager();
+        
+        // Create a new department and an employee
+        IDepartment d = createDepartment();
+        IEmployee e = createEmployee();
+        e.setDept(d);
+        e.setEmpName("John");
+        Collection<IEmployee> emps = createEmployees();
+        emps.add(e);
+        d.setEmployees(emps);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        em.clear();
+        
+        resetSQL();
+        d = findDepartment(em, d.getId());
+        // assert the select did not contain the employee table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        assertNotNull(d);
+        emps = d.getEmployees();
+        // assert there was no select
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        assertTrue(emps instanceof DelayedProxy);
+        DelayedProxy dep = (DelayedProxy)emps;
+        dep.setDirectAccess(true);
+        assertEquals(0, emps.size());
+        dep.setDirectAccess(false);
+        assertNotNull(emps);
+
+        // add an employee to the collection and remove the same employee and commit
+        resetSQL();
+        em.getTransaction().begin();
+        IEmployee e2 = createEmployee();
+        e2.setDept(d);
+        e2.setEmpName("Joe");
+        emps.add(e2);
+        emps.remove(e2);
+        em.getTransaction().commit();
+        // assert the insert into the entity and join table
+        assertNoneSQLAnyOrder("INSERT INTO DC_DEP_EMP .*");
+        assertNoneSQLAnyOrder("INSERT INTO DC_EMPLOYEE .*");
+        // assert no select from employee or dept table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*", "SELECT .* DC_DEPARTMENT .*");
+
+        // add two employees to the collection and remove one and commit
+        resetSQL();
+        em.getTransaction().begin();
+        IEmployee e3 = createEmployee();
+        e3.setDept(d);
+        e3.setEmpName("Rhonda");
+        emps.add(e3);
+
+        IEmployee e4 = createEmployee();
+        e4.setDept(d);
+        e4.setEmpName("Maria");
+        emps.add(e4);
+        emps.remove(e3);
+        em.getTransaction().commit();
+        // assert the insert into the employee and join table
+        assertAnySQLAnyOrder("INSERT INTO DC_DEP_EMP .*");
+        assertAnySQLAnyOrder("INSERT INTO DC_EMPLOYEE .*");
+        // assert no select from employee or dept table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*", "SELECT .* DC_DEPARTMENT .*");
+
+        // call contains and assert a select from the employee table
+        // occurred that the expected entities are returned.
+        resetSQL();
+        assertTrue(emps.contains(e));
+        assertFalse(emps.contains(e2));
+        assertFalse(emps.contains(e3));
+        assertTrue(emps.contains(e4));
+        assertAnySQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        resetSQL();
+        assertEquals(2, emps.size());
+        // verify a second SQL was not issued to get the size
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        em.close();
+    }
+
+    /*
+     * Verify that an eagerly loaded collection with delayed load enabled
+     * functions as expected.
+     */
+    public void testEagerCollection() {
+        EntityManager em = emf.createEntityManager();
+
+        // Create a new department and 
+        IDepartment d = createDepartment();
+        Collection<Product> products = createProducts();
+        
+        Product p = createProduct();
+        products.add(p);
+        Product p2 = createProduct();
+        products.add(p2);
+        d.setProducts(products);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        resetSQL();
+
+        em.clear();
+        
+        d = findDepartment(em, d.getId());
+        assertAnySQLAnyOrder("SELECT .* DC_DEP_PRD .*");
+        resetSQL();
+        products = d.getProducts();
+        assertTrue(products instanceof DelayedProxy);
+        ProxyCollection pxycoll = (ProxyCollection)products;
+        assertFalse(pxycoll.getOwner().isDelayed(pxycoll.getOwnerField()));
+        Product p3 = getProduct(products, 0);
+        assertTrue(products.contains(p3));
+        assertEquals(2, products.size());
+        assertNoneSQLAnyOrder("SELECT .* DC_DEPARTMENT .*", "SELECT .* DC_DEP_PRD .*");
+        em.close();
+    }
+    
+    /*
+     * Verify that a DB ordered collection is not delay load capable.
+     */
+    public void testOrderedCollection() {
+        EntityManager em = emf.createEntityManager();
+        
+        // Create a new department and persist
+        IDepartment d = createDepartment();
+        
+        Location l = createLocation();
+        Collection<Location> locs = createLocations();
+        locs.add(l);
+        d.setLocations(locs);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        
+        em.clear();
+        
+        d = findDepartment(em, d.getId());
+        assertNoneSQLAnyOrder("SELECT .* DC_DEP_LOC .*");
+        // verify that the collection is not delay loaded and does not trigger a load
+        resetSQL();
+        Collection<Location> locations = d.getLocations();
+        assertAnySQLAnyOrder("SELECT .* DC_DEP_LOC .*");
+        resetSQL();
+        assertTrue(locations instanceof DelayedProxy);
+        ProxyCollection pxycoll = (ProxyCollection)locations;
+        assertFalse(pxycoll.getOwner().isDelayed(pxycoll.getOwnerField()));
+        assertEquals(1, locations.size());
+        assertNoneSQLAnyOrder("SELECT .* DC_DEPARTMENT .*", "SELECT .* DC_DEP_LOC .*");
+        em.close();
+    }
+    
+    /*
+     * Verify that a collection will load upon serialization
+     */
+    public void testSerialization() {
+        EntityManager em = emf.createEntityManager();
+        
+        // Create a new department and an employee
+        IDepartment d = createDepartment();
+        IEmployee e = createEmployee();
+        e.setDept(d);
+        e.setEmpName("John");
+        Collection<IEmployee> emps = createEmployees();
+        emps.add(e);
+        d.setEmployees(emps);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        em.clear();
+        
+        resetSQL();
+        d = findDepartment(em, d.getId());
+        // assert the select did not contain the employee table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        assertNotNull(d);
+        emps = d.getEmployees();
+        // assert there was no select
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        assertTrue(emps instanceof DelayedProxy);
+        DelayedProxy dep = (DelayedProxy)emps;
+        dep.setDirectAccess(true);
+        assertEquals(0, emps.size());
+        dep.setDirectAccess(false);
+        assertNotNull(emps);
+
+        // add an employee to the collection
+        resetSQL();
+        em.getTransaction().begin();
+        IEmployee e2 = createEmployee();
+        e2.setDept(d);
+        e2.setEmpName("Joe");
+        emps.add(e2);
+        em.getTransaction().commit();
+        // assert the insert into the employee and join table
+        assertAnySQLAnyOrder("INSERT INTO DC_DEP_EMP .*");
+        assertAnySQLAnyOrder("INSERT INTO DC_EMPLOYEE .*");
+        // assert no select from employee or dept table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*", "SELECT .* DC_DEPARTMENT .*");
+        
+        resetSQL();
+        try {
+            // Serialize the department entity and verify the employee collection was loaded
+            IDepartment d2 = roundtrip(d);
+            assertAnySQLAnyOrder("SELECT .* DC_EMPLOYEE .*", "SELECT .* DC_DEP_EMP .*");
+            emps = d2.getEmployees();
+            assertTrue(emps.contains(e));
+            assertTrue(emps.contains(e2));
+            assertEquals(2, emps.size());
+        } catch (Exception ex) {
+            fail(ex.getMessage());
+        }
+        
+        em.close();
+    }
+    
+    /*
+     * Verify that a lazy collection of embeddables works as expected
+     * (delays load) with delayed loading enabled
+     */
+    public void testLazyEmbeddableCollection() {
+        EntityManager em = emf.createEntityManager();
+        
+        IDepartment d = createDepartment();
+        
+        Collection<Certification> certs = createCertifications();
+        certs.add(createCertification());
+        certs.add(createCertification());
+        d.setCertifications(certs);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        
+        resetSQL();
+
+        em.clear();
+        
+        d = findDepartment(em, d.getId());
+        assertNoneSQLAnyOrder("SELECT .* DC_DEP_CERT .*");
+        resetSQL();
+        certs = d.getCertifications();
+        assertNoneSQLAnyOrder("SELECT .* DC_DEP_CERT .*");
+        assertTrue(certs instanceof DelayedProxy);
+        assertEquals(2,certs.size());
+        assertAnySQLAnyOrder("SELECT .* DC_DEP_CERT .*");
+        
+        em.close();
+    }
+
+    /*
+     * Verify that an eager collection of embeddables works as expected
+     * (no delay load) with delayed loading enabled
+     */
+    public void testEagerEmbeddableCollection() {
+        EntityManager em = emf.createEntityManager();
+        
+        IDepartment d = createDepartment();
+        
+        Collection<Award> awards = createAwards();
+        awards.add(createAward());
+        awards.add(createAward());
+        awards.add(createAward());
+        d.setAwards(awards);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        
+        resetSQL();
+
+        em.clear();
+        
+        d = findDepartment(em, d.getId());
+        assertAnySQLAnyOrder("SELECT .* DC_DEP_AWD .*");
+        resetSQL();
+        awards = d.getAwards();
+        ProxyCollection pxycoll = (ProxyCollection)awards;
+        assertFalse(pxycoll.getOwner().isDelayed(pxycoll.getOwnerField()));
+        assertNoneSQLAnyOrder("SELECT .* DC_DEP_AWD .*");
+        assertTrue(awards instanceof DelayedProxy);
+        assertEquals(3,awards.size());
+        assertNoneSQLAnyOrder("SELECT .* DC_DEP_AWD .*");
+        
+        em.close();
+    }
+
+
+    /*
+     * Verify that a collection can be loaded post detachment
+     */
+    public void testPostDetach() {
+        EntityManager em = emf.createEntityManager();
+        
+        // Create a new department and an employee
+        IDepartment d = createDepartment();
+        IEmployee e = createEmployee();
+        e.setDept(d);
+        e.setEmpName("John");
+        Collection<IEmployee> emps = createEmployees();
+        emps.add(e);
+        d.setEmployees(emps);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        resetSQL();
+        em.clear();
+        
+        d = findDepartment(em, d.getId());
+        emps = d.getEmployees();
+        em.close();
+        
+        // assert there was no select on the employee table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        assertTrue(emps instanceof DelayedProxy);
+        DelayedProxy dep = (DelayedProxy)emps;
+        dep.setDirectAccess(true);
+        assertEquals(0, emps.size());
+        dep.setDirectAccess(false);
+        assertNotNull(emps);
+        // call contains and assert a select from the employee table
+        // occurred that the expected entities are returned.
+        resetSQL();
+        assertTrue(emps.contains(e));
+        e = getEmployee(emps, 0);
+        assertAnySQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        resetSQL();
+        assertEquals(1, emps.size());
+        // Verify the delay load entity is detached
+        assertTrue(e instanceof PersistenceCapable);
+        PersistenceCapable pc = (PersistenceCapable)e;
+        assertTrue(pc.pcGetStateManager() instanceof DetachedStateManager);
+        // verify a second SQL was not issued to get the size
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        
+        // add a employee to the collection and merge
+        IEmployee e2 = createEmployee();
+        e2.setDept(d);
+        emps.add(e2);
+        em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.merge(d);
+        em.getTransaction().commit();
+        emps = d.getEmployees();
+        // assert the insert into the employee and join table
+        assertAnySQLAnyOrder("INSERT INTO DC_DEP_EMP .*");
+        assertAnySQLAnyOrder("INSERT INTO DC_EMPLOYEE .*");
+        assertEquals(2, emps.size());
+        em.close();
+
+        // remove an employee from the collection and merge
+        emps.remove(e);
+        em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.merge(d);
+        em.getTransaction().commit();
+        emps = d.getEmployees();
+        
+        // assert the delete from the join table
+        assertAnySQLAnyOrder("DELETE FROM DC_DEP_EMP .*");
+        assertEquals(1, emps.size());
+        em.close();
+    }
+    
+    /*
+     * Verify that a lazy collection within an embeddable can be
+     * delayed.  The to-many in the embeddable uses 
+     */
+    public void testEmbeddableRelationship() {
+        EntityManager em = emf.createEntityManager();
+        
+        IUserIdentity ui = createUserIdentity();
+        IMember m = createMember("Member 1");
+        ui.setMember(m);
+        
+        Collection<IAccount> accounts = createAccounts();
+        IAccount checking = createAccount("Checking", ui);
+        accounts.add(checking);
+        IAccount savings = createAccount("Savings", ui);
+        accounts.add(savings);
+        
+        em.getTransaction().begin();
+        em.persist(ui);
+        em.persist(checking);
+        em.persist(savings);
+        em.getTransaction().commit();
+        
+        em.clear();
+        
+        ui = findUserIdentity(em, ui.getId());
+        
+        m = ui.getMember();
+        resetSQL();
+        accounts = m.getAccounts();
+        
+        ProxyCollection pxycoll = (ProxyCollection)accounts;
+        assertTrue(pxycoll.getOwner().isDelayed(pxycoll.getOwnerField()));
+        assertNoneSQLAnyOrder("SELECT .* DC_ACCOUNT .*");
+        assertTrue(accounts instanceof DelayedProxy);
+        // Trigger a load via iterator
+        int count = 0;
+        for (IAccount a : accounts) {
+            count++;
+        }
+        assertEquals(2,count);
+        assertAnySQLAnyOrder("SELECT .* DC_ACCOUNT .*");
+        
+        em.close();
+    }
+
+    /**
+     * Verifies proxy methods which require loading the collection will trigger a
+     * load.
+     */
+    public void testProxyMethods() {
+        // Load up a collection
+        EntityManager em = emf.createEntityManager();
+        
+        // Create a new department and employees
+        IDepartment d = createDepartment();
+        Collection<IEmployee> emps = createEmployees();
+        for (int i = 0; i < 50; i++) {
+            IEmployee e = createEmployee();
+            e.setDept(d);
+            e.setEmpName("Employee: " + i);
+            emps.add(e);
+        }
+        d.setEmployees(emps);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        em.clear();
+        
+        resetSQL();
+        
+        // build a list of public proxy methods
+        // exclude those methods that are certain not to cause a load
+        // add(Object) remove(Object), addAll(Collection), removeAll(Collection), poll?, copy()
+        Class<?> collType = emps.getClass();
+        Method[] methods = collType.getMethods();
+        for (Method m : methods) {
+            if (!excludeMethod(m)) {
+                buildAndInvoke(m, em, d.getId(), emps);
+            }
+        }
+        em.close();
+    }
+
+    private void buildAndInvoke(Method m, EntityManager em, int id, Collection<IEmployee> emps) {
+        em.clear();
+        resetSQL();
+        IDepartment d = findDepartment(em, id);
+        Collection<?> emps2 = d.getEmployees();
+        assertTrue(emps2 instanceof DelayedProxy);
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        try {
+            m.invoke(emps2, buildArgs(m, emps));
+            // not checking result or exception, just whether load was triggered
+        } catch (Throwable t) {
+            // gulp
+        }
+        if (_delayMethods.contains(stringMethodName(m))) {
+            assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        } else {
+            assertAnySQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        }
+    }
+
+    /**
+     * Build up a set of generic args just to get the basic calls through.
+     */
+    private Object[] buildArgs(Method m, Collection<?> emps) {
+        Class<?>[] parmTypes = m.getParameterTypes();
+        if (parmTypes == null) {
+            return new Object[]{};
+        }
+        int intNum = 0;
+        int objNum = 0;
+        Object[] parms = new Object[parmTypes.length];
+        for (int i = 0; i < parmTypes.length; i++) {
+            Class<?> parmType = parmTypes[i];
+            if (parmTypes[i].equals(int.class)) {
+                parms[i] = intNum;
+                intNum++;
+                continue;
+            }
+            if (parmTypes[i].equals(boolean.class)) {
+                parms[i] = true;
+                continue;
+            }
+            if (parmTypes[i].equals(Object.class)) {
+                parms[i] = emps.toArray()[objNum];
+                objNum++;
+                continue;
+            }
+            if (parmTypes[i].isAssignableFrom(Collection.class)) {
+                parms[i] = emps;
+                continue;
+            }
+        }
+        return parms;
+    }
+
+    /*
+     * Determines whether a proxy method should be invoked
+     */
+    private boolean excludeMethod(Method m) {
+        if(_ignoreInterfaces.contains(m.getDeclaringClass())) {
+            return true;
+        }
+        if (_ignoreMethods.contains(stringMethodName(m))) {
+            return true;
+        }
+        return false;
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/DelayedProxyCollectionsTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IAccount.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IAccount.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IAccount.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IAccount.java Tue May  8 19:46:20 2012
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed;
+
+public interface IAccount {
+    
+    public void setId(int id);
+
+    public int getId();
+
+    public void setName(String name);
+
+    public String getName();
+
+    public void setUserIdent(IUserIdentity userIdent);
+
+    public IUserIdentity getUserIdent();
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IAccount.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IDepartment.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IDepartment.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IDepartment.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IDepartment.java Tue May  8 19:46:20 2012
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed;
+
+import java.util.Collection;
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+public interface IDepartment { 
+
+    public void setEmployees(Collection<IEmployee> employees);
+
+    public Collection<IEmployee> getEmployees();
+    
+    public void setId(int id);
+
+    public int getId();
+
+    public void setLocations(Collection<Location> locations);
+
+    public Collection<Location> getLocations();
+
+    public void setProducts(Collection<Product> products);
+
+    public Collection<Product> getProducts();
+
+    public void setCertifications(Collection<Certification> certifications);
+
+    public Collection<Certification> getCertifications();
+
+    public void setAwards(Collection<Award> awards);
+
+    public Collection<Award> getAwards();
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IDepartment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IEmployee.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IEmployee.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IEmployee.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IEmployee.java Tue May  8 19:46:20 2012
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed;
+
+public interface IEmployee {
+
+    public void setEmpName(String empName);
+
+    public String getEmpName();
+
+    public void setId(int id);
+
+    public int getId();
+
+    public void setDept(IDepartment dept);
+
+    public IDepartment getDept();
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IEmployee.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IMember.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IMember.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IMember.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IMember.java Tue May  8 19:46:20 2012
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed;
+
+import java.util.Collection;
+
+public interface IMember {
+
+    public void setName(String name);
+
+    public String getName();
+
+    public void setAccounts(Collection<IAccount> accounts);
+
+    public Collection<IAccount> getAccounts();
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IMember.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IUserIdentity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IUserIdentity.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IUserIdentity.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IUserIdentity.java Tue May  8 19:46:20 2012
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed;
+
+public interface IUserIdentity {
+
+    public void setMember(IMember member);
+
+    public IMember getMember();
+
+    public void setId(int id);
+
+    public int getId();
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/IUserIdentity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Location.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Location.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Location.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Location.java Tue May  8 19:46:20 2012
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+
+@Entity
+@Table(name="DC_LOCATION")
+public class Location implements Serializable, Comparable<Location> {
+
+    private static final long serialVersionUID = -8396529344135184546L;
+
+    @Id
+    @GeneratedValue
+    @Column(name="LOC_ID")
+    private int id;
+
+    private String address;
+    
+    private String city;
+    
+    private String zip;
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setZip(String zip) {
+        this.zip = zip;
+    }
+
+    public String getZip() {
+        return zip;
+    }
+    
+    @Override
+    public int compareTo(Location l) {
+        return new Integer(getId()).compareTo(l.getId());
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Location.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Product.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Product.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Product.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Product.java Tue May  8 19:46:20 2012
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+
+@Entity
+public class Product implements Serializable, Comparable<Product> {
+
+    private static final long serialVersionUID = 8353220697329535861L;
+
+    @Id
+    @GeneratedValue
+    private int id;
+
+    private String name;
+    
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+    
+    @Override
+    public int compareTo(Product p) {
+        String nameId = name + id;
+        String nameId2 = p.getName() + p.getId();
+        return nameId.compareTo(nameId2);
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/Product.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Account.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Account.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Account.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Account.java Tue May  8 19:46:20 2012
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed.alist;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.proxy.delayed.IAccount;
+import org.apache.openjpa.persistence.proxy.delayed.IUserIdentity;
+
+@Entity
+@Table(name="DC_ACCOUNT")
+public class Account implements IAccount {
+
+    public Account() {
+    }
+    
+    public Account(String name, IUserIdentity uid) {
+        setName(name);
+        setUserIdent(uid);
+    }
+    
+    @Id
+    @GeneratedValue
+    @Column(name="ACCT_ID")
+    private int id;
+    
+    @ManyToOne(fetch=FetchType.LAZY)
+    @JoinColumn(name="UID_ID")
+    private UserIdentity userIdent;
+    
+    private String name;
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setUserIdent(IUserIdentity userIdent) {
+        this.userIdent = (UserIdentity)userIdent;
+    }
+
+    public IUserIdentity getUserIdent() {
+        return userIdent;
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Account.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Department.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Department.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Department.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Department.java Tue May  8 19:46:20 2012
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed.alist;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.CollectionTable;
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinTable;
+import javax.persistence.OneToMany;
+import javax.persistence.OrderColumn;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.proxy.delayed.Award;
+import org.apache.openjpa.persistence.proxy.delayed.Certification;
+import org.apache.openjpa.persistence.proxy.delayed.IDepartment;
+import org.apache.openjpa.persistence.proxy.delayed.IEmployee;
+import org.apache.openjpa.persistence.proxy.delayed.Location;
+import org.apache.openjpa.persistence.proxy.delayed.Product;
+
+@Entity
+@Table(name="DC_DEPARTMENT")
+public class Department implements IDepartment, Serializable { 
+
+    private static final long serialVersionUID = -6923551949033215888L;
+
+    @Id
+    @GeneratedValue
+    private int id;
+    
+    @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, targetEntity=Employee.class)
+    @JoinTable(name="DC_DEP_EMP")
+    private List<IEmployee> employees;
+    
+    @OrderColumn
+    @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY)
+    @JoinTable(name="DC_DEP_LOC")
+    private List<Location> locations;
+
+    @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
+    @JoinTable(name="DC_DEP_PRD")
+    private List<Product> products;
+    
+    @ElementCollection(fetch=FetchType.LAZY)
+    @CollectionTable(name="DC_DEP_CERT")
+    private List<Certification> certifications;
+
+    @ElementCollection(fetch=FetchType.EAGER)
+    @CollectionTable(name="DC_DEP_AWD")
+    private List<Award> awards;
+    
+    @Override
+    public void setEmployees(Collection<IEmployee> employees) {
+        this.employees = (List<IEmployee>)employees;
+    }
+
+    @Override
+    public Collection<IEmployee> getEmployees() {
+        return employees;
+    }
+    
+    @Override
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    @Override
+    public int getId() {
+        return id;
+    }
+
+    @Override
+    public void setLocations(Collection<Location> locations) {
+        this.locations =(List<Location>)locations;
+    }
+
+    @Override
+    public Collection<Location> getLocations() {
+        return locations;
+    }
+
+    @Override
+    public void setProducts(Collection<Product> products) {
+        this.products = (List<Product>)products;
+    }
+
+    @Override
+    public Collection<Product> getProducts() {
+        return products;
+    }
+
+    @Override
+    public void setCertifications(Collection<Certification> certifications) {
+        this.certifications = (List<Certification>)certifications;
+    }
+
+    @Override
+    public Collection<Certification> getCertifications() {
+        return certifications;
+    }
+
+    @Override
+    public void setAwards(Collection<Award> awards) {
+        this.awards = (List<Award>)awards;
+    }
+
+    @Override
+    public Collection<Award> getAwards() {
+        return awards;
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Department.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Employee.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Employee.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Employee.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Employee.java Tue May  8 19:46:20 2012
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed.alist;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.proxy.delayed.IDepartment;
+import org.apache.openjpa.persistence.proxy.delayed.IEmployee;
+
+@Entity
+@Table(name="DC_EMPLOYEE")
+public class Employee implements IEmployee, Serializable {
+
+    private static final long serialVersionUID = 1878272252981151246L;
+
+    @Id
+    @GeneratedValue
+    private int id;
+    
+    private String empName;
+    
+    @ManyToOne(targetEntity=Department.class)
+    @JoinColumn(name="DEPT_ID")
+    private IDepartment dept;
+
+    public void setEmpName(String empName) {
+        this.empName = empName;
+    }
+
+    public String getEmpName() {
+        return empName;
+    }
+
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+
+    public int getId() {
+        return id;
+    }
+
+
+    public void setDept(IDepartment dept) {
+        this.dept = dept;
+    }
+
+
+    public IDepartment getDept() {
+        return dept;
+    }
+    
+    public boolean equals(Object obj) {
+        if (obj instanceof Employee) {
+            Employee e = (Employee)obj;
+            return e.getId() == getId() && e.getEmpName().equals(getEmpName());
+        }
+        return false;
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Employee.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Member.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Member.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Member.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Member.java Tue May  8 19:46:20 2012
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed.alist;
+
+import java.util.Collection;
+import java.util.List;
+
+import javax.persistence.Embeddable;
+import javax.persistence.FetchType;
+import javax.persistence.OneToMany;
+
+import org.apache.openjpa.persistence.proxy.delayed.IAccount;
+import org.apache.openjpa.persistence.proxy.delayed.IMember;
+
+@Embeddable
+public class Member implements IMember {
+
+    private String name;
+    
+    @OneToMany(fetch=FetchType.LAZY, mappedBy="userIdent", targetEntity=Account.class)
+    private List<IAccount> accounts;
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setAccounts(Collection<IAccount> accounts) {
+        this.accounts = (List<IAccount>)accounts;
+    }
+
+    public Collection<IAccount> getAccounts() {
+        return accounts;
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/Member.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxy.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxy.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxy.java Tue May  8 19:46:20 2012
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed.alist;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.proxy.delayed.Award;
+import org.apache.openjpa.persistence.proxy.delayed.Certification;
+import org.apache.openjpa.persistence.proxy.delayed.DelayedProxyCollectionsTestCase;
+import org.apache.openjpa.persistence.proxy.delayed.IAccount;
+import org.apache.openjpa.persistence.proxy.delayed.IDepartment;
+import org.apache.openjpa.persistence.proxy.delayed.IEmployee;
+import org.apache.openjpa.persistence.proxy.delayed.IMember;
+import org.apache.openjpa.persistence.proxy.delayed.IUserIdentity;
+import org.apache.openjpa.persistence.proxy.delayed.Location;
+import org.apache.openjpa.persistence.proxy.delayed.Product;
+
+public class TestDelayedArrayListProxy extends DelayedProxyCollectionsTestCase {
+    
+    public static Object[] _pcList = { 
+        Employee.class, 
+        Department.class,
+        UserIdentity.class,
+        Member.class,
+        Account.class
+    };
+
+    public void setUp() {
+        super.setUp(_pcList);
+    }
+    
+    public void setUp(Object... props){
+        List<Object> parms = new ArrayList<Object>();
+        // Add package-specific types
+        parms.addAll(Arrays.asList(_pcList));
+        // Add properties from super
+        parms.addAll(Arrays.asList(props));
+        super.setUp(parms.toArray());
+    }
+    
+    public IUserIdentity findUserIdentity(EntityManager em, int id) {
+        return em.find(UserIdentity.class, id);
+    }
+    
+    public IDepartment findDepartment(EntityManager em, int id) {
+        return em.find(Department.class, id);
+    }
+
+    public IUserIdentity createUserIdentity() {
+        UserIdentity ui = new UserIdentity();
+        return ui;
+    }
+
+    public IAccount createAccount(String name, IUserIdentity ui) {
+        IAccount acct = new Account(name, ui);
+        return acct;
+    }
+    
+    public IDepartment createDepartment() {
+        Department d = new Department();
+        return d;
+    }
+    
+    public IMember createMember(String name) {
+        Member m = new Member();
+        m.setName(name);
+        return m;
+    }
+
+    @Override
+    public IEmployee createEmployee() {
+        Employee e = new Employee(); 
+        return e;
+    }
+
+    @Override
+    public Collection<IEmployee> createEmployees() {
+        return new ArrayList<IEmployee>();
+    }
+
+    @Override
+    public Collection<Product> createProducts() {
+        return new ArrayList<Product>();
+    }
+    
+    @Override
+    public Collection<Award> createAwards() {
+        return new ArrayList<Award>();
+    }
+    
+    @Override
+    public Collection<Location> createLocations() {
+        return new ArrayList<Location>();
+    }
+
+    @Override
+    public Collection<Certification> createCertifications() {
+        return new ArrayList<Certification>();
+    }
+
+    @Override
+    public Collection<IAccount> createAccounts() {
+        return new ArrayList<IAccount>();
+    }
+
+    @Override
+    public IEmployee getEmployee(Collection<IEmployee> emps, int idx) {
+        return ((List<IEmployee>)emps).get(idx);
+    }
+
+    @Override
+    public Product getProduct(Collection<Product> products, int idx) {
+        return ((List<Product>)products).get(idx);
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxyDetachLite.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxyDetachLite.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxyDetachLite.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxyDetachLite.java Tue May  8 19:46:20 2012
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed.alist;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.persistence.proxy.delayed.DelayedProxyCollectionsTestCase;
+import org.apache.openjpa.persistence.proxy.delayed.IDepartment;
+import org.apache.openjpa.persistence.proxy.delayed.IEmployee;
+import org.apache.openjpa.util.DelayedArrayListProxy;
+
+public class TestDelayedArrayListProxyDetachLite extends TestDelayedArrayListProxy {
+
+    @Override
+    public void setUp() {
+        super.setUp(
+                "openjpa.DetachState", "loaded(LiteAutoDetach=true,detachProxyFields=false)");
+    }
+    
+    /*
+     * Verify that a collection can be loaded post detachment
+     */
+    @Override
+    public void testPostDetach() {
+        EntityManager em = emf.createEntityManager();
+        
+        // Create a new department and an employee
+        IDepartment d = createDepartment();
+        IEmployee e = createEmployee();
+        e.setDept(d);
+        e.setEmpName("John");
+        Collection<IEmployee> emps = createEmployees();
+        emps.add(e);
+        d.setEmployees(emps);
+        
+        em.getTransaction().begin();
+        em.persist(d);
+        em.getTransaction().commit();
+        resetSQL();
+        em.clear();
+        
+        d = findDepartment(em, d.getId());
+        emps = d.getEmployees();
+        em.close();
+        
+        // assert there was no select on the employee table
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        assertTrue(emps instanceof DelayedArrayListProxy);
+        DelayedArrayListProxy dep = (DelayedArrayListProxy)emps;
+        dep.setDirectAccess(true);
+        assertEquals(0, dep.size());
+        dep.setDirectAccess(false);
+        assertNotNull(emps);
+        // call contains and assert a select from the employee table
+        // occurred that the expected entities are returned.
+        resetSQL();
+        assertTrue(emps.contains(e));
+        e = getEmployee(emps,0);
+        assertAnySQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+        resetSQL();
+        assertEquals(1, emps.size());
+        // Verify the delay load entity is detached
+        assertTrue(e instanceof PersistenceCapable);
+        PersistenceCapable pc = (PersistenceCapable)e;
+        // LiteAutoDetach
+        assertTrue(pc.pcGetStateManager() == null);
+        // verify a second SQL was not issued to get the size
+        assertNoneSQLAnyOrder("SELECT .* DC_EMPLOYEE .*");
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/TestDelayedArrayListProxyDetachLite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/UserIdentity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/UserIdentity.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/UserIdentity.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/UserIdentity.java Tue May  8 19:46:20 2012
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed.alist;
+
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.proxy.delayed.IMember;
+import org.apache.openjpa.persistence.proxy.delayed.IUserIdentity;
+
+@Entity
+@Table(name="DC_UIDENT")
+public class UserIdentity implements IUserIdentity {
+
+    @Id
+    @GeneratedValue
+    @Column(name="UID_ID")
+    private int id;
+
+    @Embedded
+    private Member member;
+
+    public void setMember(IMember member) {
+        this.member = (Member)member;
+    }
+
+    public IMember getMember() {
+        return member;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/alist/UserIdentity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Account.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Account.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Account.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Account.java Tue May  8 19:46:20 2012
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed.hset;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.proxy.delayed.IAccount;
+import org.apache.openjpa.persistence.proxy.delayed.IUserIdentity;
+
+@Entity
+@Table(name="DC_ACCOUNT")
+public class Account implements IAccount {
+
+    public Account() {
+    }
+    
+    public Account(String name, IUserIdentity uid) {
+        setName(name);
+        setUserIdent(uid);
+    }
+    
+    @Id
+    @GeneratedValue
+    @Column(name="ACCT_ID")
+    private int id;
+    
+    @ManyToOne(fetch=FetchType.LAZY)
+    @JoinColumn(name="UID_ID")
+    private UserIdentity userIdent;
+    
+    private String name;
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setUserIdent(IUserIdentity userIdent) {
+        this.userIdent = (UserIdentity)userIdent;
+    }
+
+    public IUserIdentity getUserIdent() {
+        return userIdent;
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Account.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Department.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Department.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Department.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Department.java Tue May  8 19:46:20 2012
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed.hset;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.CollectionTable;
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinTable;
+import javax.persistence.OneToMany;
+import javax.persistence.OrderColumn;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.proxy.delayed.Award;
+import org.apache.openjpa.persistence.proxy.delayed.Certification;
+import org.apache.openjpa.persistence.proxy.delayed.IDepartment;
+import org.apache.openjpa.persistence.proxy.delayed.IEmployee;
+import org.apache.openjpa.persistence.proxy.delayed.Location;
+import org.apache.openjpa.persistence.proxy.delayed.Product;
+
+@Entity
+@Table(name="DC_DEPARTMENT")
+public class Department implements IDepartment, Serializable { 
+
+    private static final long serialVersionUID = -6923551949033215888L;
+
+    @Id
+    @GeneratedValue
+    private int id;
+    
+    @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, targetEntity=Employee.class)
+    @JoinTable(name="DC_DEP_EMP")
+    private Set<IEmployee> employees;
+    
+    @OrderColumn
+    @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY)
+    @JoinTable(name="DC_DEP_LOC")
+    private Set<Location> locations;
+
+    @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
+    @JoinTable(name="DC_DEP_PRD")
+    private Set<Product> products;
+    
+    @ElementCollection(fetch=FetchType.LAZY)
+    @CollectionTable(name="DC_DEP_CERT")
+    private Set<Certification> certifications;
+
+    @ElementCollection(fetch=FetchType.EAGER)
+    @CollectionTable(name="DC_DEP_AWD")
+    private Set<Award> awards;
+    
+    @Override
+    public void setEmployees(Collection<IEmployee> employees) {
+        this.employees = (Set<IEmployee>)employees;
+    }
+
+    @Override
+    public Collection<IEmployee> getEmployees() {
+        return employees;
+    }
+    
+    @Override
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    @Override
+    public int getId() {
+        return id;
+    }
+
+    @Override
+    public void setLocations(Collection<Location> locations) {
+        this.locations =(Set<Location>)locations;
+    }
+
+    @Override
+    public Collection<Location> getLocations() {
+        return locations;
+    }
+
+    @Override
+    public void setProducts(Collection<Product> products) {
+        this.products = (Set<Product>)products;
+    }
+
+    @Override
+    public Collection<Product> getProducts() {
+        return products;
+    }
+
+    @Override
+    public void setCertifications(Collection<Certification> certifications) {
+        this.certifications = (Set<Certification>)certifications;
+    }
+
+    @Override
+    public Collection<Certification> getCertifications() {
+        return certifications;
+    }
+
+    @Override
+    public void setAwards(Collection<Award> awards) {
+        this.awards = (Set<Award>)awards;
+    }
+
+    @Override
+    public Collection<Award> getAwards() {
+        return awards;
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Department.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Employee.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Employee.java?rev=1335720&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Employee.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Employee.java Tue May  8 19:46:20 2012
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.proxy.delayed.hset;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.proxy.delayed.IDepartment;
+import org.apache.openjpa.persistence.proxy.delayed.IEmployee;
+
+@Entity
+@Table(name="DC_EMPLOYEE")
+public class Employee implements IEmployee, Serializable {
+
+    private static final long serialVersionUID = 1878272252981151246L;
+
+    @Id
+    @GeneratedValue
+    private int id;
+    
+    private String empName;
+    
+    @ManyToOne(targetEntity=Department.class)
+    @JoinColumn(name="DEPT_ID")
+    private IDepartment dept;
+
+    public void setEmpName(String empName) {
+        this.empName = empName;
+    }
+
+    public String getEmpName() {
+        return empName;
+    }
+
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+
+    public int getId() {
+        return id;
+    }
+
+
+    public void setDept(IDepartment dept) {
+        this.dept = dept;
+    }
+
+
+    public IDepartment getDept() {
+        return dept;
+    }
+    
+    @Override
+    public int hashCode() {
+        return getId();
+    }
+    
+    public boolean equals(Object obj) {
+        if (obj instanceof Employee) {
+            Employee e = (Employee)obj;
+            return e.getId() == getId() && e.getEmpName().equals(getEmpName());
+        }
+        return false;
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/delayed/hset/Employee.java
------------------------------------------------------------------------------
    svn:eol-style = native