mirror of https://github.com/apache/openjpa.git
OPENJPA-2132 Fix empty List for OneToMany with InheritanceType.JOINED or SINGLE_TABLE
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1298856 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e1c4c92888
commit
f94fb7f727
|
@ -1157,7 +1157,11 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
|
||||||
private boolean getJoinedSupers(Select sel, ClassMapping mapping, int subs, boolean outer) {
|
private boolean getJoinedSupers(Select sel, ClassMapping mapping, int subs, boolean outer) {
|
||||||
loadSubclasses(mapping);
|
loadSubclasses(mapping);
|
||||||
Joins joins = (outer) ? sel.newOuterJoins() : null;
|
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,
|
private boolean needClassCondition(ClassMapping mapping, int subs,
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue