You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2009/10/21 17:57:01 UTC
svn commit: r828072 - in /openjpa/trunk:
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/
openjpa-persistence-jdbc/src/test/resources/META-INF/ openjpa-...
Author: curtisr7
Date: Wed Oct 21 15:57:00 2009
New Revision: 828072
URL: http://svn.apache.org/viewvc?rev=828072&view=rev
Log:
OPENJPA-859: Recommitting 818928. Added new test scenario for partial xml defined embeddable that implements Serializable.
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestMixedMappingLocation.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocationEmbeddedId.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/orm.xml (with props)
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestMixedMappingLocation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestMixedMappingLocation.java?rev=828072&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestMixedMappingLocation.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestMixedMappingLocation.java Wed Oct 21 15:57:00 2009
@@ -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();
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestMixedMappingLocation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java?rev=828072&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java Wed Oct 21 15:57:00 2009
@@ -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;
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocationEmbeddedId.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocationEmbeddedId.java?rev=828072&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocationEmbeddedId.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocationEmbeddedId.java Wed Oct 21 15:57:00 2009
@@ -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();
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocationEmbeddedId.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/orm.xml?rev=828072&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/orm.xml (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/orm.xml Wed Oct 21 15:57:00 2009
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="1.0">
+ <entity class="org.apache.openjpa.persistence.entity.MixedMappingLocation">
+ <attributes>
+ <embedded-id name="id"></embedded-id>
+ <basic name="basic1">
+ <column name="basic1_override" length="100"/>
+ </basic>
+ </attributes>
+ </entity>
+ <embeddable class="org.apache.openjpa.persistence.entity.MixedMappingLocationEmbeddedId"></embeddable>
+</entity-mappings>
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/orm.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=828072&r1=828071&r2=828072&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Wed Oct 21 15:57:00 2009
@@ -254,7 +254,13 @@
<persistence-unit name="mdr-pu">
<class>org.apache.openjpa.persistence.meta.MdrTestEntity</class>
- </persistence-unit>
+ </persistence-unit>
+
+ <persistence-unit name="test_parsing">
+ <mapping-file>org/apache/openjpa/persistence/entity/orm.xml</mapping-file>
+ <class>org.apache.openjpa.persistence.entity.MixedMappingLocation</class>
+ <class>org.apache.openjpa.persistence.entity.MixedMappingLocationEmbeddedId</class>
+ </persistence-unit>
<persistence-unit name="mapsId-pu">
<mapping-file>org/apache/openjpa/persistence/enhance/identity/mapsId-orm.xml</mapping-file>
Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=828072&r1=828071&r2=828072&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java Wed Oct 21 15:57:00 2009
@@ -491,21 +491,22 @@
* 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;
Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?rev=828072&r1=828071&r2=828072&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java Wed Oct 21 15:57:00 2009
@@ -1063,6 +1063,7 @@
fmd.setExplicit(true);
fmd.setPrimaryKey(true);
fmd.setEmbedded(true);
+ fmd.setSerialized(false);
if (fmd.getEmbeddedMetaData() == null)
// fmd.addEmbeddedMetaData();
deferEmbeddable(fmd.getDeclaredType(), fmd);