Author: ppoddar
Date: Tue Jan 22 14:37:21 2013
New Revision: 1436960

URL: http://svn.apache.org/viewvc?rev=1436960&view=rev
Log:
OPENJPA-2325: Test cases for Mapped Super Class without identity field

Added:
    
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/DerivedEntityFromMappedSuperWithoutId.java
   (with props)
    
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/MappedSuperWithoutId.java
   (with props)
Modified:
    
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java

Added: 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/DerivedEntityFromMappedSuperWithoutId.java
URL: 
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/DerivedEntityFromMappedSuperWithoutId.java?rev=1436960&view=auto
==============================================================================
--- 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/DerivedEntityFromMappedSuperWithoutId.java
 (added)
+++ 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/DerivedEntityFromMappedSuperWithoutId.java
 Tue Jan 22 14:37:21 2013
@@ -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.mappedsuperclass;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Version;
+
+/**
+ * A Mapped Super Class without a declared identity field. The derived classes
+ * declare identity.
+ * 
+ * @author Pinaki Poddar
+ * 
+ */
+
+@Entity
+public class DerivedEntityFromMappedSuperWithoutId extends 
MappedSuperWithoutId {
+       @Id
+       private long id;
+
+       private String name;
+
+       @Version
+       private int version;
+
+       public long getId() {
+               return id;
+       }
+
+       public void setId(long id) {
+               this.id = id;
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public int getVersion() {
+               return version;
+       }
+
+       public void setVersion(int version) {
+               this.version = version;
+       }
+}

Propchange: 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/DerivedEntityFromMappedSuperWithoutId.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/MappedSuperWithoutId.java
URL: 
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/MappedSuperWithoutId.java?rev=1436960&view=auto
==============================================================================
--- 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/MappedSuperWithoutId.java
 (added)
+++ 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/MappedSuperWithoutId.java
 Tue Jan 22 14:37:21 2013
@@ -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.persistence.inheritance.mappedsuperclass;
+
+import javax.persistence.MappedSuperclass;
+
+/**
+ * A Mapped Super Class without a declared identity field. The derived classes
+ * declare identity.
+ * 
+ * @author Pinaki Poddar
+ * 
+ */
+
+@MappedSuperclass
+public class MappedSuperWithoutId {
+       private String description;
+
+       public String getDesc() {
+               return description;
+       }
+
+       public void setDesc(String desc) {
+               this.description = desc;
+       }
+}

Propchange: 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/MappedSuperWithoutId.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java
URL: 
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java?rev=1436960&r1=1436959&r2=1436960&view=diff
==============================================================================
--- 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java
 (original)
+++ 
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java
 Tue Jan 22 14:37:21 2013
@@ -28,16 +28,22 @@ import org.apache.openjpa.persistence.te
 /**
  * Test case and domain classes were originally part of the reported issue
  * <A href="https://issues.apache.org/jira/browse/OPENJPA-873";>OPENJPA-873</A>
- *  
+ * <p>
+ * Added a new test where mapped super class does not decalre an identity.
+ * Originally reported 
+ * <A 
href="https://issues.apache.org/jira/browse/OPENJPA-2325";>OPENJPA-2325</A>
+ * 
  * @author [email protected]
  * @author Fay Wang
- *
+ * @author Pinaki Poddar
  */
 public class TestMappedSuperClass extends SingleEMFTestCase {
 
     public void setUp() {
         setUp(CashBaseEntity.class, 
-              SituationDA.class, ValuableItemDA.class, CLEAR_TABLES);
+              SituationDA.class, ValuableItemDA.class, 
+              MappedSuperWithoutId.class, 
DerivedEntityFromMappedSuperWithoutId.class,
+              CLEAR_TABLES);
     }
 
     public void testMappedSuperClass() {
@@ -73,4 +79,35 @@ public class TestMappedSuperClass extend
             em.close();
         }
     }
+    
+    /**
+     * Tests that new entity can be merged when the entity is derived from a 
mapped
+     * super class that does not declare an identity field.
+     */
+    public void 
testMergeNewInstanceDerivedFromMappedSuperClassWithoutIdentityField() {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        final long id = System.currentTimeMillis();
+               DerivedEntityFromMappedSuperWithoutId pc = new 
DerivedEntityFromMappedSuperWithoutId();
+               pc.setId(id);
+               pc.setName("abc");
+               em.persist(pc);
+               em.getTransaction().commit();
+               em.close();
+       
+               DerivedEntityFromMappedSuperWithoutId newpc = new 
DerivedEntityFromMappedSuperWithoutId();
+               em = emf.createEntityManager();
+        em.getTransaction().begin();
+               newpc.setId(id);
+               newpc.setName("xyz");
+               em.merge(newpc);
+               em.getTransaction().commit();
+               em.close();
+               
+               em = emf.createEntityManager();
+               DerivedEntityFromMappedSuperWithoutId found = 
em.find(DerivedEntityFromMappedSuperWithoutId.class, id);
+               assertNotNull(found);
+               assertEquals("xyz", found.getName());
+               
+    }
 }


Reply via email to