diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
index bd56b81fe..8e9679f4c 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
@@ -39,6 +39,10 @@ public class InheritanceComparator
_base = base;
}
+ public Class getBase() {
+ return _base;
+ }
+
/**
* Subclasses can override this method to extract the class to compare
* on from the elements of the collection.
diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
index 41bd19012..1a5aea3b5 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
@@ -574,6 +574,7 @@ public class MetaDataRepository
* if we're still in the process of resolving other metadatas.
*/
private List resolveMeta(ClassMetaData meta) {
+ setBaseIfNecessary(meta);
if (meta.getPCSuperclass() == null) {
// set superclass
Class sup = meta.getDescribedType().getSuperclass();
@@ -616,6 +617,27 @@ public class MetaDataRepository
// resolved
return processBuffer(meta, _resolving, MODE_META);
}
+
+ private void setBaseIfNecessary(ClassMetaData meta) {
+ if (_resolving == null)
+ return;
+
+ InheritanceComparator comp =
+ (InheritanceComparator) _resolving.comparator();
+ if (meta.getPCSuperclass() == null) {
+ Class sup = meta.getDescribedType().getSuperclass();
+ Class pBase = null;
+ while (sup != null && sup != Object.class) {
+ pBase = sup;
+ sup = sup.getSuperclass();
+ }
+ if (pBase != null && !pBase.equals(comp.getBase())) {
+ // setBase() can be called because getMetaData() is
+ // syncronized
+ comp.setBase(pBase);
+ }
+ }
+ }
/**
* Load mapping information for the given metadata.
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
new file mode 100644
index 000000000..32c093774
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Artist.java
@@ -0,0 +1,42 @@
+/*
+ * 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.meta;
+
+import javax.persistence.Entity;
+
+@Entity
+public class Artist
+ extends Person {
+
+ /**
+ * Default constructor required for enhancement.
+ */
+ public Artist() {
+ super();
+ }
+
+ /**
+ * The public constructor constructs with a name.
+ *
+ * @param name the name of the artist.
+ */
+ public Artist(String name) {
+ super(name);
+ }
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
new file mode 100644
index 000000000..e7e045055
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Item.java
@@ -0,0 +1,110 @@
+/*
+ * 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.meta;
+
+import java.io.Serializable;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+@Entity
+public class Item implements Serializable {
+
+ @Id
+ @GeneratedValue
+ private int id;
+
+ private String title;
+
+ @ManyToOne(cascade = CascadeType.PERSIST)
+ private Artist artist;
+
+ /**
+ * A no-arg constructor is required for enhancement.
+ */
+ protected Item() {
+ super();
+ }
+
+ /**
+ * The public constructor constructs with a title.
+ *
+ * @param title the title of the item.
+ */
+ public Item(String title) {
+ super();
+ this.title = title;
+ }
+
+ /**
+ * Gets the unique identifier of this receiver. There is no corresponding
+ * setId()
method as the identifier value is generated by the
+ * Persistence Provider Runtime.
+ *
+ * @return unique identifier of this instance.
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * Gets the title of this item.
+ *
+ * @return return the tile of the item.
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * Sets the title of this receiver.
+ *
+ * @param title must not be null or empty.
+ */
+ public void setTitle(String title) {
+ if (title == null || title.trim().length() == 0)
+ throw new IllegalArgumentException(
+ "null or empty title not allowed");
+ this.title = title;
+ }
+
+ /**
+ * Gets the artist who created this item. This is an example of
+ * unidirectional single-valued relationship.
+ *
+ * @return the artist who created this item.
+ */
+ public Artist getArtist() {
+ return artist;
+ }
+
+ /**
+ * Sets the artist who created this Item.
+ *
+ * @param artist must not be null.
+ */
+ public void setArtist(Artist artist) {
+ if (artist == null)
+ throw new IllegalArgumentException("null Artist for " + this);
+
+ this.artist = artist;
+ }
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
new file mode 100644
index 000000000..e85c46b64
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Painter.java
@@ -0,0 +1,33 @@
+/*
+ * 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.meta;
+
+import javax.persistence.Entity;
+
+@Entity
+public class Painter extends Artist {
+
+ public Painter() {
+ super();
+ }
+
+ public Painter(String name) {
+ super(name);
+ }
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
new file mode 100644
index 000000000..49e99f867
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/Person.java
@@ -0,0 +1,78 @@
+/*
+ * 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.meta;
+
+import java.io.Serializable;
+import java.util.Collection;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+@Entity
+public class Person implements Serializable {
+
+ @Id
+ private String name;
+
+ @OneToMany
+ private Collection paitersForPortrait;
+
+ /**
+ * default constructor required by enhancement.
+ */
+ protected Person() {
+
+ }
+
+ /**
+ * The public constructor constructs with a name.
+ *
+ * @param name the name of the person.
+ */
+
+ public Person(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Gets the name of this person. This is the unique identifier.
+ *
+ * @return return the name of this person.
+ */
+ public String getName() {
+
+ return name;
+ }
+
+ public void setName(String name) {
+ if (name == null || name.trim().length() == 0)
+ throw new IllegalArgumentException(
+ "null or empty name not allowed");
+ this.name = name;
+ }
+
+ public Collection getPainters() {
+
+ return paitersForPortrait;
+ }
+
+ public void setPainters(Collection p) {
+ this.paitersForPortrait = p;
+ }
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
new file mode 100644
index 000000000..943938584
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestGetMetaData.java
@@ -0,0 +1,35 @@
+/*
+ * 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.meta;
+
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestGetMetaData extends SingleEMFTestCase {
+
+ public void setUp() {
+ setUp(Item.class, Person.class, Artist.class, Painter.class,
+ CLEAR_TABLES);
+ }
+
+ public void testGetMetaData() {
+ assertNotNull(JPAFacadeHelper.getMetaData(emf, Item.class));
+ assertNotNull(JPAFacadeHelper.getMetaData(emf, Person.class));
+ }
+}