openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r895788 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/
Date Mon, 04 Jan 2010 21:17:35 GMT
Author: faywang
Date: Mon Jan  4 21:17:35 2010
New Revision: 895788

URL: http://svn.apache.org/viewvc?rev=895788&view=rev
Log:
OPENJPA-1020: fix class cast exception when retrieving eager persistent collection

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringEager.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringLazy.java
  (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java?rev=895788&r1=895787&r2=895788&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
Mon Jan  4 21:17:35 2010
@@ -407,7 +407,7 @@
         // Check if the owner has eagerly loaded ToMany relations.
         for (int i = 0; i < fms.length; i++) {
             if (res.getEager(fms[i]) != null) {
-                if (fms[i].isElementCollection() && !fms[i].getElement().isTypePC())
+                if (!fms[i].getElement().isTypePC())
                     continue;
                 Object coll =  owner.fetchObject(fms[i].getIndex());
                 if (coll instanceof Map)

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringEager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringEager.java?rev=895788&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringEager.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringEager.java
Mon Jan  4 21:17:35 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.annotations;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+
+import org.apache.openjpa.persistence.PersistentCollection;
+
+@Entity
+public class PColl_EntityStringEager {
+
+    @Id
+    private int id;
+
+    @PersistentCollection(fetch=FetchType.EAGER)
+    private Set<String> collectionOfStrings = new HashSet<String>();
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Set<String> getCollectionOfStrings() {
+        return collectionOfStrings;
+    }
+
+    public void setCollectionOfStrings(Set<String> collectionOfStrings) {
+        this.collectionOfStrings = collectionOfStrings;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringEager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringLazy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringLazy.java?rev=895788&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringLazy.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringLazy.java
Mon Jan  4 21:17:35 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.annotations;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+
+import org.apache.openjpa.persistence.PersistentCollection;
+
+@Entity
+public class PColl_EntityStringLazy {
+
+    @Id
+    private int id;
+
+    @PersistentCollection(fetch=FetchType.LAZY)
+    private Set<String> collectionOfStrings = new HashSet<String>();
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Set<String> getCollectionOfStrings() {
+        return collectionOfStrings;
+    }
+
+    public void setCollectionOfStrings(Set<String> collectionOfStrings) {
+        this.collectionOfStrings = collectionOfStrings;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/PColl_EntityStringLazy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java?rev=895788&r1=895787&r2=895788&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPersistentCollection.java
Mon Jan  4 21:17:35 2010
@@ -35,7 +35,8 @@
 
     public void setUp() {
         setUp(PColl_EntityA.class, PColl_EmbedB.class, PColl_EntityC.class,
-                PColl_EntityA1.class, PColl_EntityB.class, CLEAR_TABLES);
+                PColl_EntityA1.class, PColl_EntityB.class, PColl_EntityStringEager.class,
+                PColl_EntityStringLazy.class, CLEAR_TABLES);
     }
 
     @SuppressWarnings("unchecked")
@@ -116,4 +117,56 @@
             fail(t.getMessage());
         }
     }    
+
+    public void testPersistentCollectionStringsLazy() {
+        try {
+            EntityManager em = emf.createEntityManager();
+
+            em.getTransaction().begin();
+
+            PColl_EntityStringLazy a = new PColl_EntityStringLazy();
+            a.setId(1);
+            a.getCollectionOfStrings().add("one");
+            em.persist(a);
+            em.getTransaction().commit();
+            em.close();
+            
+            em = emf.createEntityManager();
+            Query q = em.createQuery("SELECT o FROM PColl_EntityStringLazy o"); 
+            PColl_EntityStringLazy a1 = (PColl_EntityStringLazy)q.getSingleResult();
+            
+            assertEquals(1, a1.getCollectionOfStrings().size());
+            assertEquals("one", a1.getCollectionOfStrings().toArray()[0]);
+            assertEquals(1, a1.getId());
+            em.close();
+        } catch (Throwable t) {
+            fail(t.getMessage());
+        }
+    }    
+
+    public void testPersistentCollectionStringsEager() {
+        try {
+            EntityManager em = emf.createEntityManager();
+
+            em.getTransaction().begin();
+
+            PColl_EntityStringEager a = new PColl_EntityStringEager();
+            a.setId(1);
+            a.getCollectionOfStrings().add("one");
+            em.persist(a);
+            em.getTransaction().commit();
+            em.close();
+            
+            em = emf.createEntityManager();
+            Query q = em.createQuery("SELECT o FROM PColl_EntityStringEager o"); 
+            PColl_EntityStringEager a1 = (PColl_EntityStringEager)q.getSingleResult();
+            
+            assertEquals(1, a1.getCollectionOfStrings().size());
+            assertEquals("one", a1.getCollectionOfStrings().toArray()[0]);
+            assertEquals(1, a1.getId());
+            em.close();
+        } catch (Throwable t) {
+            fail(t.getMessage());
+        }
+    }    
 }



Mime
View raw message