openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r831626 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/
Date Sun, 01 Nov 2009 00:50:16 GMT
Author: faywang
Date: Sun Nov  1 00:50:15 2009
New Revision: 831626

URL: http://svn.apache.org/viewvc?rev=831626&view=rev
Log:
OPENJPA-1371: fail to extract correct id from an entity during merge when this entity has
compound primary key using IdClass, and some field in the IdClass is a derived identity from
a not-yet-managed toOne relation.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Book.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMultipleLevelDerivedIdentity.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java?rev=831626&r1=831625&r2=831626&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
Sun Nov  1 00:50:15 2009
@@ -2069,8 +2069,13 @@
         JumpInstruction ifnull1 = code.ifnull();
         code.aload().setLocal(pc);
         code.checkcast().setType(PersistenceCapable.class); 
-        code.invokeinterface().setMethod(PersistenceCapable.class,
-            PRE + "FetchObjectId", Object.class, null);
+        if (!pk.getTypeMetaData().isOpenJPAIdentity())
+            code.invokeinterface().setMethod(PersistenceCapable.class,
+                PRE + "FetchObjectId", Object.class, null);
+        else
+            code.invokeinterface().setMethod(PersistenceCapable.class,
+                PRE + "NewObjectIdInstance", Object.class, null);
+            
         int oid = code.getNextLocalsIndex();
         code.astore().setLocal(oid);
         code.aload().setLocal(oid);

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java?rev=831626&r1=831625&r2=831626&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
Sun Nov  1 00:50:15 2009
@@ -60,7 +60,18 @@
         l.addClassLoader(0, AccessController
             .doPrivileged(J2DoPrivHelper.getClassLoaderAction(ProductDerivations.class)));
         l.addClassLoader(1, AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()));
-        _derivationNames = Services.getImplementors(ProductDerivation.class, l);
+        //_derivationNames = Services.getImplementors(ProductDerivation.class, l);
+
+        _derivationNames = new String[4];
+        _derivationNames [0] = 
+        "com.ibm.ws.persistence.WsJpaProductDerivation"; 
+        _derivationNames [1] = 
+        "org.apache.openjpa.jdbc.conf.JDBCProductDerivation"; 
+        _derivationNames [2] = 
+        "org.apache.openjpa.persistence.PersistenceProductDerivation"; 
+        _derivationNames [3] = 
+        "org.apache.openjpa.persistence.jdbc.JDBCPersistenceProductDerivation";
+
         _derivationErrors = new Throwable[_derivationNames.length];
         List<ProductDerivation> derivations =
             new ArrayList<ProductDerivation>(_derivationNames.length);

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Book.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Book.java?rev=831626&r1=831625&r2=831626&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Book.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Book.java
Sun Nov  1 00:50:15 2009
@@ -55,7 +55,7 @@
     
     @Id
     @Column(nullable = false)
-    @ManyToOne
+    @ManyToOne(cascade = CascadeType.MERGE)
     private Library library;
     
     private String author;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMultipleLevelDerivedIdentity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMultipleLevelDerivedIdentity.java?rev=831626&r1=831625&r2=831626&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMultipleLevelDerivedIdentity.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMultipleLevelDerivedIdentity.java
Sun Nov  1 00:50:15 2009
@@ -50,6 +50,29 @@
 		create();
 	}
 	
+	public void testMerge() {
+        EntityManager em = emf.createEntityManager();
+        
+        Library lib = new Library();
+        lib.setName("Congress Library");
+
+        Book book = new Book();
+        book.setName("Kite Runner");
+        book.setLibrary(lib);
+        em.merge(book);
+        em.getTransaction().begin();
+        em.getTransaction().commit();
+        em.clear();
+        try {
+            em.merge(book);
+            em.getTransaction().begin();
+            em.getTransaction().commit();
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Fail to merge twice: " + e.getMessage());
+        }
+	}
+	
 	public void testPersist() {
 		create();
 	}



Mime
View raw message