Author: epbernard
Date: 2007-01-23 14:23:13 -0500 (Tue, 23 Jan 2007)
New Revision: 11083
Added:
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Colony.java
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Empire.java
Modified:
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java
Log:
test on merging a managed object
Added:
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Colony.java
===================================================================
---
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Colony.java
(rev 0)
+++
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Colony.java 2007-01-23
19:23:13 UTC (rev 11083)
@@ -0,0 +1,25 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Colony {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+}
Added:
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Empire.java
===================================================================
---
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Empire.java
(rev 0)
+++
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Empire.java 2007-01-23
19:23:13 UTC (rev 11083)
@@ -0,0 +1,39 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.OneToMany;
+import javax.persistence.CascadeType;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Empire {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @OneToMany(cascade= CascadeType.ALL )
+ private Set<Colony> colonies = new HashSet<Colony>();
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Set<Colony> getColonies() {
+ return colonies;
+ }
+
+ public void setColonies(Set<Colony> colonies) {
+ this.colonies = colonies;
+ }
+}
Modified:
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2007-01-23
17:12:25 UTC (rev 11082)
+++
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2007-01-23
19:23:13 UTC (rev 11083)
@@ -140,11 +140,32 @@
em.close();
}
+ public void testMergeUnidirectionalOneToMany() throws Exception {
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ Empire roman = new Empire();
+ em.persist( roman );
+ em.flush();
+ em.clear();
+ roman = em.find( Empire.class, roman.getId() );
+ Colony gaule = new Colony();
+ roman.getColonies().add(gaule);
+ em.merge( roman );
+ em.flush();
+ em.clear();
+ roman = em.find(Empire.class, roman.getId() );
+ assertEquals( 1, roman.getColonies().size() );
+ em.getTransaction().rollback();
+ em.close();
+ }
+
public Class[] getAnnotatedClasses() {
return new Class[] {
Race.class,
Competitor.class,
- Competition.class
+ Competition.class,
+ Empire.class,
+ Colony.class
};
}
}
Show replies by date