From 46bd7173793260e2cf38563bee000af35a13061f Mon Sep 17 00:00:00 2001 From: Mark Struberg Date: Mon, 4 Nov 2013 00:00:42 +0000 Subject: [PATCH] OPENJPA-2335 add a unit test for demonstrating the bug git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.3.x@1538480 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/persistence/TestOpenJPA2330.java | 20 +++++++++++++++++++ .../openjpa/persistence/criteria/Course.java | 1 - .../openjpa/persistence/entity/EntityA.java | 2 +- .../openjpa/persistence/entity/EntityB.java | 5 +++++ 4 files changed, 26 insertions(+), 2 deletions(-) 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 45e41e67f..cfedde71b 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 @@ -21,11 +21,14 @@ package org.apache.openjpa.persistence; import javax.persistence.EntityManager; import javax.persistence.spi.LoadState; +import junit.framework.Assert; import org.apache.openjpa.persistence.entity.EntityA; import org.apache.openjpa.persistence.entity.EntityB; import org.apache.openjpa.persistence.entity.EntityC; import org.apache.openjpa.persistence.test.SingleEMFTestCase; +import java.util.Iterator; + /** * */ @@ -55,4 +58,21 @@ public class TestOpenJPA2330 extends SingleEMFTestCase { em.close(); } + + public void testOpenJPA2335() { + EntityManager em = emf.createEntityManager(); + + em.getTransaction().begin(); + EntityA a = new EntityA(); + EntityB b1 = new EntityB(a); + EntityB b2 = new EntityB(a); + a.getBs().add(b1); + a.getBs().add(b2); + + em.persist(a); + + em.getTransaction().commit(); + em.close(); + + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course.java index 576073af2..74e23c3bd 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Course.java @@ -29,7 +29,6 @@ import javax.persistence.Table; @Entity @Table(name="CR_CRSE") - public class Course { @Id @GeneratedValue diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/EntityA.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/EntityA.java index 7dca9558e..2257d82f0 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/EntityA.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/entity/EntityA.java @@ -42,7 +42,7 @@ public class EntityA implements Serializable { private String name; @OneToMany(fetch = FetchType.EAGER, mappedBy = "center", orphanRemoval = true, cascade = CascadeType.ALL) - @OrderColumn + @OrderColumn(name="POSITION") private Set services = new LinkedHashSet(); public EntityA() { 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 bd3c2862e..4d57aa1c5 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 @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; @@ -47,6 +48,10 @@ public class EntityB { @OrderColumn private Set linacs; + @Column(name = "POSITION") + private int position; + + public EntityB() { }