openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r588533 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java
Date Fri, 26 Oct 2007 05:39:49 GMT
Author: pcl
Date: Thu Oct 25 22:39:48 2007
New Revision: 588533

URL: http://svn.apache.org/viewvc?rev=588533&view=rev
Log:
OPENJPA-419

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java?rev=588533&r1=588532&r2=588533&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
Thu Oct 25 22:39:48 2007
@@ -268,7 +268,10 @@
         OpenJPAStateManager sm, ValueMetaData vmd) {
         if (toAttach == null)
             return null;
-        if (manager.getBroker().isDetached(toAttach)) {
+
+        if (manager.getBroker().isPersistent(toAttach)) {
+            return toAttach;
+        } else if (manager.getBroker().isDetached(toAttach)) {
             Object oid = manager.getDetachedObjectId(toAttach);
             if (oid != null)
                 return manager.getBroker().find(oid, false, null);

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java?rev=588533&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java
Thu Oct 25 22:39:48 2007
@@ -0,0 +1,75 @@
+/*
+ * 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.lifecycle;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.relations.BidiChild;
+import org.apache.openjpa.persistence.relations.BidiParent;
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
+
+public class TestMergeAndPersistWithManagedRelation
+    extends SingleEMTestCase {
+
+    private long childId;
+
+    public void setUp() {
+        setUp(BidiParent.class, BidiChild.class, CLEAR_TABLES);
+
+        BidiChild child = new BidiChild();
+        child.setName("child");
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.persist(child);
+        em.getTransaction().commit();
+        childId = child.getId();
+        em.close();
+    }
+
+    public void testPersistWithManagedRelation() {
+        BidiParent parent = new BidiParent();
+        BidiChild child = em.find(BidiChild.class, childId);
+        parent.setOneToOneChild(child);
+        em.getTransaction().begin();
+        em.persist(parent);
+        em.getTransaction().commit();
+        long id = parent.getId();
+        em.close();
+
+        em = emf.createEntityManager();
+        parent = em.find(BidiParent.class, id);
+        assertNotNull(parent);
+    }
+
+    public void testMergeWithManagedRelation() {
+        BidiParent parent = new BidiParent();
+        BidiChild child = em.find(BidiChild.class, childId);
+        parent.setOneToOneChild(child);
+        em.getTransaction().begin();
+        parent = em.merge(parent);
+        em.getTransaction().commit();
+        long id = parent.getId();
+        em.close();
+
+        em = emf.createEntityManager();
+        parent = em.find(BidiParent.class, id);
+        assertNotNull(parent);
+    }
+}
\ No newline at end of file



Mime
View raw message