Author: dianner
Date: Fri Mar 9 14:46:44 2012
New Revision: 1298856
URL: http://svn.apache.org/viewvc?rev=1298856&view=rev
Log:
OPENJPA-2132 Fix empty List for OneToMany with InheritanceType.JOINED or
SINGLE_TABLE
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/TestJointableOneToMany.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLClass.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLNamed.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPackage.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPrimitiveType.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLType.java
(with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.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=1298856&r1=1298855&r2=1298856&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
Fri Mar 9 14:46:44 2012
@@ -1157,7 +1157,11 @@ public class JDBCStoreManager implements
private boolean getJoinedSupers(Select sel, ClassMapping mapping, int
subs, boolean outer) {
loadSubclasses(mapping);
Joins joins = (outer) ? sel.newOuterJoins() : null;
- return mapping.getDiscriminator().addClassConditions(sel, subs ==
Select.SUBS_JOINABLE, joins);
+ boolean includeSubs = false;
+ if (subs == Select.SUBS_JOINABLE || subs == Select.SUBS_ANY_JOINABLE) {
+ includeSubs = true;
+ }
+ return mapping.getDiscriminator().addClassConditions(sel, includeSubs,
joins);
}
private boolean needClassCondition(ClassMapping mapping, int subs,
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/TestJointableOneToMany.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/TestJointableOneToMany.java?rev=1298856&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/TestJointableOneToMany.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/TestJointableOneToMany.java
Fri Mar 9 14:46:44 2012
@@ -0,0 +1,124 @@
+/*
+ * 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.inheritance.jointable.onetomany;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Test an inheritance type of 'joinable' where a OneToMany relationship is
used
+ * to get a parent class.
+ */
+public class TestJointableOneToMany extends SingleEMFTestCase {
+
+ public void setUp() {
+ setUp(UMLType.class, UMLPrimitiveType.class, UMLClass.class,
+ UMLPackage.class, UMLNamed.class, CLEAR_TABLES);
+ initialize();
+ }
+
+ public void initialize() {
+ EntityManager em = emf.createEntityManager();
+ try {
+ UMLPackage aPackage =
+ em.find(UMLPackage.class, "org.apache.openjpa");
+ if (null == aPackage) {
+ EntityTransaction tx = em.getTransaction();
+ tx.begin();
+
+ // Create a UMLPackage
+ aPackage = new UMLPackage();
+ aPackage.setId("org.apache.openjpa");
+ aPackage.setName("org.apache.openjpa");
+ aPackage.setOwnedType(new ArrayList<UMLType>());
+ em.persist(aPackage);
+
+ // Create a UMLClass and add the UMLPackage to it.
+ UMLClass aClass = new UMLClass();
+ aClass.setId("org.apache.openjpa.ATestClass");
+ aClass.setName("TesClass");
+ aClass.setOwnerPackage(aPackage);
+ em.persist(aClass);
+
+ // Add UMLClass to UMLPackage
+ aPackage.getOwnedType().add(aClass);
+ em.merge(aPackage);
+ // TODO: temp
+ // em.persist(aPackage);
+
+ // Create a UMLPrimativeType and add UMLPackage to it.
+ UMLPrimitiveType primitiveType = new UMLPrimitiveType();
+ primitiveType.setId("String");
+ primitiveType.setName("String");
+ primitiveType.setOwnerPackage(aPackage);
+ em.persist(primitiveType);
+
+ // Add UMLPrimativeType to UMLPackage
+ aPackage.getOwnedType().add(primitiveType);
+ em.merge(aPackage);
+ // TODO: temp
+ // em.persist(aPackage);
+
+ tx.commit();
+ }
+ } finally {
+ em.close();
+ }
+ }
+
+ public void test() {
+ EntityManager em = emf.createEntityManager();
+ try {
+ // Verify the Class exists, and that from it we can get the
Package.
+ UMLClass aClass =
+ em.find(UMLClass.class, "org.apache.openjpa.ATestClass");
+ assertNotNull(aClass);
+ assertEquals("org.apache.openjpa", aClass.getOwnerPackage()
+ .getName());
+
+ // Verify the PrimitiveType exists, and that from it we can get the
+ // Package.
+ UMLPrimitiveType aPrimitiveType =
+ em.find(UMLPrimitiveType.class, "String");
+ assertNotNull(aPrimitiveType);
+ assertEquals("org.apache.openjpa", aPrimitiveType.getOwnerPackage()
+ .getName());
+
+ // Verify the Package exists.
+ UMLPackage aPackage =
+ em.find(UMLPackage.class, "org.apache.openjpa");
+ assertNotNull(aPackage);
+
+ // From the Package, lets get the Type.....there should be two
+ // Types (i.e. a UMLClass and UMLPrimativeTYpe), but 0 is returned!
+ List<UMLType> ownedType = aPackage.getOwnedType();
+ assertNotNull(ownedType);
+ assertEquals(2, ownedType.size());
+
+ } finally {
+ em.close();
+
+ }
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/TestJointableOneToMany.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLClass.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLClass.java?rev=1298856&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLClass.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLClass.java
Fri Mar 9 14:46:44 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.inheritance.jointable.onetomany;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+
+@Entity
+public class UMLClass extends UMLType implements Serializable {
+
+
+ private static final long serialVersionUID = 1L;
+
+ public UMLClass() {
+ super();
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLNamed.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLNamed.java?rev=1298856&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLNamed.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLNamed.java
Fri Mar 9 14:46:44 2012
@@ -0,0 +1,59 @@
+/*
+ * 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.inheritance.jointable.onetomany;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+@Entity
+@Inheritance(strategy=InheritanceType.JOINED)
+public class UMLNamed implements Serializable {
+
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ private String id;
+
+ private String name;
+
+ public UMLNamed() {
+ super();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLNamed.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPackage.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPackage.java?rev=1298856&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPackage.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPackage.java
Fri Mar 9 14:46:44 2012
@@ -0,0 +1,67 @@
+/*
+ * 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.inheritance.jointable.onetomany;
+
+import java.io.Serializable;
+import java.util.List;
+
+import javax.persistence.*;
+
+@Entity
+//@Inheritance(strategy = InheritanceType.JOINED)
+public class UMLPackage implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ private String id;
+
+ private String name;
+
+ @OneToMany(mappedBy = "ownerPackage")
+ private List<UMLType> ownedType;
+
+ public UMLPackage() {
+ super();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List<UMLType> getOwnedType() {
+ return ownedType;
+ }
+
+ public void setOwnedType(List<UMLType> ownedType) {
+ this.ownedType = ownedType;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPackage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPrimitiveType.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPrimitiveType.java?rev=1298856&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPrimitiveType.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPrimitiveType.java
Fri Mar 9 14:46:44 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.inheritance.jointable.onetomany;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+
+@Entity
+public class UMLPrimitiveType extends UMLType implements Serializable {
+
+
+ private static final long serialVersionUID = 1L;
+
+ public UMLPrimitiveType() {
+ super();
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLPrimitiveType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLType.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLType.java?rev=1298856&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLType.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLType.java
Fri Mar 9 14:46:44 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.inheritance.jointable.onetomany;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.ManyToOne;
+
+@Entity
+public class UMLType extends UMLNamed implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @ManyToOne
+ private UMLPackage ownerPackage;
+
+ public UMLType() {
+ super();
+ }
+
+ public UMLPackage getOwnerPackage() {
+ return ownerPackage;
+ }
+
+ public void setOwnerPackage(UMLPackage ownerPackage) {
+ this.ownerPackage = ownerPackage;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/onetomany/UMLType.java
------------------------------------------------------------------------------
svn:eol-style = native