diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java index e29b96e54..9e54843e2 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java @@ -2283,7 +2283,12 @@ public class PCEnhancer { code.getstatic().setField(PRE + "FieldTypes", Class[].class); code.getstatic().setField(PRE + "FieldFlags", byte[].class); code.getstatic().setField(SUPER, Class.class); - code.constant().setValue(_meta.getTypeAlias()); + + if (_meta.isMapped()) + code.constant().setValue(_meta.getTypeAlias()); + else + code.constant().setNull(); + if (_pc.isAbstract()) code.constant().setNull(); else { 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 e5711b300..b0507da68 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 @@ -1396,14 +1396,16 @@ public class MetaDataRepository // set alias for class String alias = PCRegistry.getTypeAlias(cls); - synchronized (_aliases) { - List classList = (List) _aliases.get(alias); - if (classList == null) { - classList = new ArrayList(3); - _aliases.put(alias, classList); + if (alias != null) { + synchronized (_aliases) { + List classList = (List) _aliases.get(alias); + if (classList == null) { + classList = new ArrayList(3); + _aliases.put(alias, classList); + } + if (!classList.contains(cls)) + classList.add(cls); } - if (!classList.contains(cls)) - classList.add(cls); } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedUnqualifiedClassNames.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedUnqualifiedClassNames.java new file mode 100644 index 000000000..d0b5d4b74 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedUnqualifiedClassNames.java @@ -0,0 +1,59 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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; + +import org.apache.openjpa.persistence.test.SingleEMFTestCase; +import org.apache.openjpa.persistence.OpenJPAPersistence; +import org.apache.openjpa.meta.ClassMetaData; +import org.apache.openjpa.kernel.AbstractBrokerFactory; + +/** + * Test that entities, mapped superclasses, and embeddables can all share + * the same short names without any collisions. + */ +public class TestSharedUnqualifiedClassNames + extends SingleEMFTestCase { + + public void setUp() { + setUp(org.apache.openjpa.persistence.inheritance.mappedsuperclass + .SharedName1.class, + org.apache.openjpa.persistence.inheritance.entity + .SharedName1.class, + org.apache.openjpa.persistence.inheritance.embeddable + .SharedName2.class, + org.apache.openjpa.persistence.inheritance.entity + .SharedName2.class); + emf.createEntityManager().close(); + } + + public void testMappedSuperclass() { + ClassMetaData meta = emf.getConfiguration() + .getMetaDataRepositoryInstance() + .getMetaData("SharedName1", getClass().getClassLoader(), true); + assertEquals( + org.apache.openjpa.persistence.inheritance.entity.SharedName1.class, + meta.getDescribedType()); + } + + public void testEmbeddable() { + ClassMetaData meta = emf.getConfiguration() + .getMetaDataRepositoryInstance() + .getMetaData("SharedName2", getClass().getClassLoader(), true); + assertEquals( + org.apache.openjpa.persistence.inheritance.entity.SharedName2.class, + meta.getDescribedType()); + } +}