openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1470097 - in /openjpa/branches/2.2.1.x: ./ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/
Date Sat, 20 Apr 2013 02:18:33 GMT
Author: hthomann
Date: Sat Apr 20 02:18:32 2013
New Revision: 1470097

URL: http://svn.apache.org/r1470097
Log:
OPENJPA-2325: MappedSuperClass without an @Id causes wrong identity type for the inherited
types - back-ported to 2.2.1.x Pinaki Poddar's commit to trunk.

Added:
    openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/DerivedEntityFromMappedSuperWithoutId.java
      - copied unchanged from r1469949, openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/DerivedEntityFromMappedSuperWithoutId.java
    openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/MappedSuperWithoutId.java
      - copied unchanged from r1469949, openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/MappedSuperWithoutId.java
Modified:
    openjpa/branches/2.2.1.x/   (props changed)
    openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java

Propchange: openjpa/branches/2.2.1.x/
------------------------------------------------------------------------------
  Merged /openjpa/branches/2.1.x:r1469949
  Merged /openjpa/trunk:r1436957,1436960

Modified: openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=1470097&r1=1470096&r2=1470097&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Sat Apr 20 02:18:32 2013
@@ -179,7 +179,7 @@ public class ClassMetaData
     private List<Class<?>> _interfaces = null;
     private final Map<Class<?>,Map<String,String>> _ifaceMap = 
     	new HashMap<Class<?>,Map<String,String>>();
-    private int _identity = ID_UNKNOWN;
+    private Integer _identity = null;
     private int _idStrategy = ValueStrategies.NONE;
     private int _accessType = AccessCode.UNKNOWN;
     
@@ -440,21 +440,25 @@ public class ClassMetaData
      * primary key fields, and {@link #ID_APPLICATION} otherwise.
      */
     public int getIdentityType() {
-        if (_identity == ID_UNKNOWN) {
-            ClassMetaData sup = getPCSuperclassMetaData();
-            if (sup != null && sup.getIdentityType() != ID_UNKNOWN)
-                _identity = sup.getIdentityType();
-            else if (getPrimaryKeyFields().length > 0)
-                _identity = ID_APPLICATION;
-            else if (isMapped())
-                _identity = ID_DATASTORE;
-            else
-                _identity = _repos.getMetaDataFactory().getDefaults().
-                    getDefaultIdentityType();
-        }
+    	if (_identity != null) {
+    		return _identity;
+    	} else {
+    		ClassMetaData sup = getPCSuperclassMetaData();
+	        if (sup != null && sup.getIdentityType() != ID_UNKNOWN) 
+	            _identity = sup.getIdentityType();
+	        else if (getPrimaryKeyFields().length > 0) 
+	            _identity = ID_APPLICATION;
+	        else if (isMapped()) 
+	            _identity = ID_DATASTORE;
+	        else if (isAbstract())
+	        	_identity = ID_UNKNOWN;
+	        else
+	            _identity = _repos.getMetaDataFactory().getDefaults().
+	            	 getDefaultIdentityType();
+    	}
         return _identity;
     }
-
+  
     /**
      * The type of identity being used. This will be one of:
      * <ul>
@@ -2511,8 +2515,9 @@ public class ClassMetaData
         _embeddable = meta._embeddable;
         _interface = (meta.isManagedInterface()) ? Boolean.TRUE : Boolean.FALSE;
         setIntercepting(meta.isIntercepting());
+        _abstract = meta.isAbstract();
         _impl = meta.getInterfaceImpl();
-        _identity = meta.getIdentityType();
+        _identity = meta._identity == null ? null : meta.getIdentityType();
         _idStrategy = meta.getIdentityStrategy();
         _seqName = meta.getIdentitySequenceName();
         _seqMeta = null;

Modified: openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java?rev=1470097&r1=1470096&r2=1470097&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java
Sat Apr 20 02:18:32 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 pioneer_ip@yahoo.com
  * @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());
+		
+    }
 }



Mime
View raw message