Author: rpalache
Date: Wed Oct 26 17:08:27 2011
New Revision: 1189317
URL: http://svn.apache.org/viewvc?rev=1189317&view=rev
Log:
OPENJPA-2066 Edge case in openJPA-1227. openJPA fails to create a join and thus
returns wrong data when a collection is selected from superclass and another
field is selected from subclass two or more levels down the hierarchy
Added:
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ChildChildClass.java
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ChildClass.java
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/GrandChildClass.java
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ParentClass.java
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestJoinedMultiInheritanceHierarchy.java
Modified:
openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
Modified:
openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java?rev=1189317&r1=1189316&r2=1189317&view=diff
==============================================================================
---
openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
(original)
+++
openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
Wed Oct 26 17:08:27 2011
@@ -1148,7 +1148,7 @@ public class JDBCStoreManager
// in certain circumstances force join to superclass table to avoid
// SQL generation error.
- if ( eagerToMany != null && pseld < 0 && seld > 0 && !joined
+ if ( eagerToMany != null && pseld < 0 && !joined
&& parent != null ) {
FieldMapping[] pfms = parent.getDefinedFieldMappings();
for (int i = 0; i < pfms.length; i++) {
Added:
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ChildChildClass.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ChildChildClass.java?rev=1189317&view=auto
==============================================================================
---
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ChildChildClass.java
(added)
+++
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ChildChildClass.java
Wed Oct 26 17:08:27 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.relations;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import org.apache.openjpa.persistence.FetchAttribute;
+import org.apache.openjpa.persistence.FetchGroup;
+import org.apache.openjpa.persistence.FetchGroups;
+
+@Entity
+@Inheritance(strategy=InheritanceType.JOINED)
+@FetchGroups({
+ @FetchGroup(name = "ccc", attributes = {
+ @FetchAttribute(name = "name2")
+ })
+ })
+public class ChildChildClass extends ChildClass {
+
+ private String name2;
+
+ public ChildChildClass() {
+ super();
+ }
+
+ public String getName2() {
+ return name2;
+ }
+
+ public void setName2(String name2) {
+ this.name2 = name2;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString()+"\n"+"Name2: "+name2+"\n";
+ }
+}
+
Added:
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ChildClass.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ChildClass.java?rev=1189317&view=auto
==============================================================================
---
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ChildClass.java
(added)
+++
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ChildClass.java
Wed Oct 26 17:08:27 2011
@@ -0,0 +1,69 @@
+/*
+ * 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.relations;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import org.apache.openjpa.persistence.FetchAttribute;
+import org.apache.openjpa.persistence.FetchGroup;
+import org.apache.openjpa.persistence.FetchGroups;
+
+@Entity
+@Inheritance(strategy=InheritanceType.JOINED)
+@FetchGroups({
+ @FetchGroup(name = "cc", attributes = {
+ @FetchAttribute(name = "name")
+ })
+ })
+public class ChildClass extends ParentClass {
+
+ private String name;
+
+ public ChildClass() {
+ super();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sBuf = new StringBuilder();
+ sBuf.append("Name: ").append(name).append("\n");
+ sBuf.append("Items: ");
+ if (getItems().isEmpty()) {
+ sBuf.append("none\n");
+ } else {
+ sBuf.append(getItems().size()).append('\n');
+ for (String item : getItems()) {
+ sBuf.append("\t");
+ sBuf.append(item);
+ sBuf.append("\n");
+ }
+ }
+ return sBuf.toString();
+ }
+}
Added:
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/GrandChildClass.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/GrandChildClass.java?rev=1189317&view=auto
==============================================================================
---
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/GrandChildClass.java
(added)
+++
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/GrandChildClass.java
Wed Oct 26 17:08:27 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.relations;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+@Entity
+@Inheritance(strategy=InheritanceType.JOINED)
+public class GrandChildClass extends ChildChildClass {
+
+ private String someUnloadedField;
+
+ public String getSomeUnloadedString() {
+ return someUnloadedField;
+ }
+
+ public String toString() {
+ return super.toString() + "SomeUnloadedField: " + someUnloadedField +
"\n";
+ }
+}
Added:
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ParentClass.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ParentClass.java?rev=1189317&view=auto
==============================================================================
---
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ParentClass.java
(added)
+++
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ParentClass.java
Wed Oct 26 17:08:27 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.relations;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Collection;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+import org.apache.openjpa.persistence.PersistentCollection;
+
+@Entity
+@Inheritance(strategy=InheritanceType.JOINED)
+public abstract class ParentClass {
+
+ @PersistentCollection
+ private Set<String> items = new HashSet<String>();
+
+ protected ParentClass() {
+ }
+
+ public Set<String> getItems() {
+ return items;
+ }
+
+ public void setItems(Collection<String> items) {
+ this.items.addAll(items);
+ }
+}
Added:
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestJoinedMultiInheritanceHierarchy.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestJoinedMultiInheritanceHierarchy.java?rev=1189317&view=auto
==============================================================================
---
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestJoinedMultiInheritanceHierarchy.java
(added)
+++
openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestJoinedMultiInheritanceHierarchy.java
Wed Oct 26 17:08:27 2011
@@ -0,0 +1,73 @@
+/*
+ * 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.relations;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Collection;
+
+import org.apache.openjpa.meta.FetchGroup;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.PersistenceException;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestJoinedMultiInheritanceHierarchy
+ extends SingleEMFTestCase {
+
+ public void setUp() {
+ super.setUp( CLEAR_TABLES, ChildChildClass.class, ChildClass.class,
+ GrandChildClass.class, ParentClass.class,
+ "openjpa.BrokerImpl", "EvictFromDataCache=true",
+ "openjpa.Log", "Enhance=ERROR,SQL=TRACE");
+ }
+
+ public void testCacheSqlGeneration() throws PersistenceException {
+ OpenJPAEntityManager em = emf.createEntityManager();
+
+ em.getTransaction().begin();
+ final GrandChildClass notEmpty = new GrandChildClass();
+ notEmpty.setName("Not empty object");
+ Collection<String> itemSet = notEmpty.getItems();
+ for (int i = 0; i < 5; i++) {
+ itemSet.add(notEmpty.getName() + " : item n." + i);
+ }
+
+ notEmpty.setItems(itemSet);
+
+ final GrandChildClass empty = new GrandChildClass();
+ empty.setName("empty object");
+
+ em.persist(notEmpty);
+ em.persist(empty);
+ em.getTransaction().commit();
+
+ em.evictAll();
+ em.getFetchPlan().clearFetchGroups();
+ em.getFetchPlan().addField(ParentClass.class, "items");
+ em.getFetchPlan().addField(GrandChildClass.class, "someUnloadedField");
+ assert empty.getItems().isEmpty() : empty.getName()
+ + " should be empty !";
+ }
+
+ public void tearDown() throws Exception {
+ }
+}
+