openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r617695 - in /openjpa/branches/1.0.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/
Date Fri, 01 Feb 2008 23:03:15 GMT
Author: mikedd
Date: Fri Feb  1 15:03:05 2008
New Revision: 617695

URL: http://svn.apache.org/viewvc?rev=617695&view=rev
Log:
OPENJPA-419 Ported to 1.0.x. 

Added:
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java
  (with props)
Modified:
    openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java

Modified: openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java?rev=617695&r1=617694&r2=617695&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
(original)
+++ openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
Fri Feb  1 15:03:05 2008
@@ -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/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java?rev=617695&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java
(added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java
Fri Feb  1 15:03:05 2008
@@ -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);
+    }
+}

Propchange: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/lifecycle/TestMergeAndPersistWithManagedRelation.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message