From 979d8f24e9313b2895672ad30613d4d5e57774ca Mon Sep 17 00:00:00 2001 From: Mark Struberg Date: Sat, 9 Nov 2013 19:26:31 +0000 Subject: [PATCH] OPENJPA-2335 review test case and update checks git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.3.x@1540371 13f79535-47bb-0310-9956-ffa450edef68 --- .../RelationToManyInverseKeyFieldStrategy.java | 8 +++++--- .../openjpa/persistence/TestOpenJPA2330.java | 14 ++++++++++---- .../apache/openjpa/persistence/entity/EntityB.java | 4 ---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java index d7b7ea539..abe3e9127 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java @@ -327,8 +327,7 @@ public abstract class RelationToManyInverseKeyFieldStrategy if (sm != null && sm.isDeleted()) sm = null; writeable = io.isAnyUpdatable(fk, sm == null); - orderWriteable = field.getOrderColumnIO().isUpdatable - (order, sm == null); + orderWriteable = field.getOrderColumnIO().isUpdatable(order, sm == null); action = Row.ACTION_UPDATE; } if (!writeable && !orderWriteable) @@ -345,8 +344,11 @@ public abstract class RelationToManyInverseKeyFieldStrategy // update the inverse pointer with our oid value if (writeable) row.setForeignKey(fk, io, sm); - if (orderWriteable) + + if (orderWriteable) { + // set the OrderColumn value row.setInt(order, idx); + } } public Object toDataStoreValue(Object val, JDBCStore store) { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestOpenJPA2330.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestOpenJPA2330.java index a081e16e6..db5cc1310 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestOpenJPA2330.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestOpenJPA2330.java @@ -67,19 +67,18 @@ public class TestOpenJPA2330 extends SingleEMFTestCase { EntityB b1 = new EntityB(a); b1.setName("b1"); + a.getBs().add(b1); EntityB b2 = new EntityB(a); b2.setName("b2"); + a.getBs().add(b2); EntityB b3 = new EntityB(a); b3.setName("b3"); + a.getBs().add(b3); EntityB b4 = new EntityB(a); b4.setName("b4"); - - a.getBs().add(b1); - a.getBs().add(b2); - a.getBs().add(b3); a.getBs().add(b4); em.persist(a); @@ -95,6 +94,13 @@ public class TestOpenJPA2330 extends SingleEMFTestCase { Assert.assertNotNull(a2.getBs()); Assert.assertEquals(4, a2.getBs().size()); + Iterator it = a2.getBs().iterator(); + for (int i = 1; i <= 4; i++) { + EntityB entityB = it.next(); + + Assert.assertEquals("b" + i, entityB.getName()); + } + em.getTransaction().commit(); em.close(); } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/EntityB.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/EntityB.java index 4d57aa1c5..943aeadf2 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/EntityB.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/EntityB.java @@ -48,10 +48,6 @@ public class EntityB { @OrderColumn private Set linacs; - @Column(name = "POSITION") - private int position; - - public EntityB() { }