Revision: 9933
http://datanucleus.svn.sourceforge.net/datanucleus/?rev=9933&view=rev
Author: andy_jefferson
Date: 2010-05-23 07:28:23 +0000 (Sun, 23 May 2010)
Log Message:
-----------
[NUCJPA-70] Test for 1-1 orphanRemoval when deleting the object and expecting the related object to be deleted too
Modified Paths:
--------------
test/accessplatform/trunk/test.jpa.general/src/test/org/datanucleus/tests/RelationshipsTest.java
Modified: test/accessplatform/trunk/test.jpa.general/src/test/org/datanucleus/tests/RelationshipsTest.java
===================================================================
--- test/accessplatform/trunk/test.jpa.general/src/test/org/datanucleus/tests/RelationshipsTest.java 2010-05-23 07:03:49 UTC (rev 9932)
+++ test/accessplatform/trunk/test.jpa.general/src/test/org/datanucleus/tests/RelationshipsTest.java 2010-05-23 07:28:23 UTC (rev 9933)
@@ -609,7 +609,7 @@
/**
* Test of 1-1 Uni relation, and use of orphanRemoval
*/
- public void testOneToOneUniWithOrphanRemoval()
+ public void testOneToOneUniWithOrphanRemovalAndNulling()
{
try
{
@@ -713,4 +713,108 @@
clean(Login.class);
}
}
+ /**
+ * Test of 1-1 Uni relation, and use of orphanRemoval
+ */
+ public void testOneToOneUniWithOrphanRemovalAndDeleting()
+ {
+ try
+ {
+ EntityManager em = getEM();
+ EntityTransaction tx = em.getTransaction();
+ try
+ {
+ tx.begin();
+
+ LoginAccount acct = new LoginAccount(1, "Bill", "Gates");
+ Login login = new Login("billy", "$$$$$$");
+ login.setId(1);
+ acct.setLogin(login);
+ em.persist(acct);
+
+ tx.commit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("Exception thrown while creating Login and LoginAccount");
+ }
+ finally
+ {
+ if (tx.isActive())
+ {
+ tx.rollback();
+ }
+ em.close();
+ }
+
+ // Check the contents of the datastore, and trigger orphanRemoval by nulling
+ em = getEM();
+ tx = em.getTransaction();
+ try
+ {
+ tx.begin();
+
+ LoginAccount acct = em.find(LoginAccount.class, new Long(1));
+ assertEquals("LoginAccount has incorrect firstName", "Bill", acct.getFirstName());
+ assertEquals("LoginAccount has incorrect lastName", "Gates", acct.getLastName());
+ assertNotNull(acct.getLogin());
+ Login login = acct.getLogin();
+ assertEquals("Login has incorrect username", "billy", login.getUserName());
+ assertEquals("Login has incorrect password", "$$$$$$", login.getPassword());
+
+ // Delete the LoginAccount object so we can trigger orphanRemoval
+ em.remove(acct);
+
+ tx.commit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("Exception thrown while retrieving Login and LoginAccount and deleting LoginAccount");
+ }
+ finally
+ {
+ if (tx.isActive())
+ {
+ tx.rollback();
+ }
+ em.close();
+ }
+
+ // Check the contents of the datastore
+ em = getEM();
+ tx = em.getTransaction();
+ try
+ {
+ tx.begin();
+
+ Login login = em.find(Login.class, new Long(1));
+ assertNull("Login should have been deleted but still exists", login);
+
+ LoginAccount acct = em.find(LoginAccount.class, new Long(1));
+ assertNull("LoginAccount should have been deleted but still exists", acct);
+
+ tx.commit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("Exception thrown while retrieving Login and LoginAccount");
+ }
+ finally
+ {
+ if (tx.isActive())
+ {
+ tx.rollback();
+ }
+ em.close();
+ }
+ }
+ finally
+ {
+ clean(LoginAccount.class);
+ clean(Login.class);
+ }
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|