diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestMixedMappingLocation.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestMixedMappingLocation.java new file mode 100644 index 000000000..2af56454f --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestMixedMappingLocation.java @@ -0,0 +1,50 @@ +/* + * 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/LICENSE2.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; + +import javax.persistence.Entity; + +import org.apache.openjpa.persistence.entity.MixedMappingLocation; +import org.apache.openjpa.persistence.entity.MixedMappingLocationEmbeddedId; +import org.apache.openjpa.persistence.test.SingleEMFTestCase; + +// org.apache.openjpa.persistence.TestMixedMappingLocation +@Entity +public class TestMixedMappingLocation extends SingleEMFTestCase { + + @Override + protected String getPersistenceUnitName() { + return "test_parsing"; + } + public void setUp() { + setUp(DROP_TABLES,MixedMappingLocationEmbeddedId.class, MixedMappingLocation.class); + } + /** + * Testcase for added OPENJPA859. + * + * This scenario is testing whether the default annotations are being generated for a class that + * isn't annotated with a persistence class type (ie: @Entity, @MappedSuperclass, @Embeddable), + * but it is in a mapping file. + * + * @throws Exception + */ + public void testMixedOrmAnno() throws Exception { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java new file mode 100644 index 000000000..a50af0676 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.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/LICENSE2.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.entity; + +import javax.persistence.Basic; + +/** + * This class doesn't have an @Entity and @Basic on purpose. + */ +public class MixedMappingLocation { + MixedMappingLocationEmbeddedId id; + + String basic1; + + @Basic + String basic2; +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocationEmbeddedId.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocationEmbeddedId.java new file mode 100644 index 000000000..47bea3d11 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocationEmbeddedId.java @@ -0,0 +1,53 @@ +/* + * 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/LICENSE2.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.entity; + +import java.io.Serializable; + +import javax.persistence.Basic; +import javax.persistence.Transient; + +public class MixedMappingLocationEmbeddedId implements Serializable { + @Transient + private static final long serialVersionUID = 1L; + @Basic + private int id; + @Basic + private String country; + + public MixedMappingLocationEmbeddedId() { + // TODO Auto-generated constructor stub + } + + public int getId() { + return id; + } + + @Override + public boolean equals(Object obj) { + // TODO Auto-generated method stub + return super.equals(obj); + } + + @Override + public int hashCode() { + // TODO Auto-generated method stub + return super.hashCode(); + } +} diff --git a/openjpa-persistence-jdbc/src/test/resources/META-INF/orm.xml b/openjpa-persistence-jdbc/src/test/resources/META-INF/orm.xml new file mode 100644 index 000000000..ead3a400a --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/resources/META-INF/orm.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + diff --git a/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml b/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml index eca54ac7c..9ec4908a0 100644 --- a/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml +++ b/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml @@ -254,7 +254,13 @@ org.apache.openjpa.persistence.meta.MdrTestEntity - + + + + org/apache/openjpa/persistence/entity/orm.xml + org.apache.openjpa.persistence.entity.MixedMappingLocation + org.apache.openjpa.persistence.entity.MixedMappingLocationEmbeddedId + org/apache/openjpa/persistence/enhance/identity/mapsId-orm.xml diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java index 8ccb024a8..06db4ab93 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java @@ -491,21 +491,22 @@ public class AnnotationPersistenceMetaDataParser * Read annotations for the current type. */ private ClassMetaData parseClassAnnotations() { - // check immediately whether the user is using any annotations, - // regardless of mode. this prevents adding non-entity classes to - // repository if we're ignoring these annotations in mapping mode - if (!(AccessController.doPrivileged(J2DoPrivHelper - .isAnnotationPresentAction(_cls, Entity.class))).booleanValue() - && !(AccessController.doPrivileged(J2DoPrivHelper - .isAnnotationPresentAction(_cls, Embeddable.class))) + // Check to see if there is cached metadata for the class that we are currently parsing. It + // is possible that one of the annotations (Entity, Embeddable, MappedSuperclass) is in the + // orm.xml. We still need to look at these files for other annotations and more importantly + // setup defaults (ie: Basic fields). + ClassMetaData m = getRepository().getCachedMetaData(_cls); + if (m == null) { + if (!(AccessController.doPrivileged(J2DoPrivHelper.isAnnotationPresentAction(_cls, Entity.class))) .booleanValue() - && !(AccessController.doPrivileged(J2DoPrivHelper - .isAnnotationPresentAction(_cls, MappedSuperclass.class))) - .booleanValue()) - return null; - + && !(AccessController.doPrivileged(J2DoPrivHelper.isAnnotationPresentAction(_cls, Embeddable.class))) + .booleanValue() + && !(AccessController.doPrivileged(J2DoPrivHelper.isAnnotationPresentAction(_cls, + MappedSuperclass.class))).booleanValue()) + return null; + } // find / create metadata - ClassMetaData meta = getMetaData(); + ClassMetaData meta = (m == null) ? getMetaData() : m; if (meta == null) return null; diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java index 6cc6587bf..d44531564 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java @@ -1063,6 +1063,7 @@ public class XMLPersistenceMetaDataParser fmd.setExplicit(true); fmd.setPrimaryKey(true); fmd.setEmbedded(true); + fmd.setSerialized(false); if (fmd.getEmbeddedMetaData() == null) // fmd.addEmbeddedMetaData(); deferEmbeddable(fmd.getDeclaredType(), fmd);