Revision 492013 (http://svn.apache.org/viewvc?view=rev&rev=492013) modified these pojos to maintain both sides of relationships in the constructor. Going through rest of roller code, it seems to be more consistent to maintain these relationships from respective mangers. I am proposing to rollback these changes. Attached is a patch that rollback the changes to these pojos. Please note that Hibernate does not enforce maintaining relationships from both sides hence no code in Hibernate*ManagerImpl is changed.

I have successfully run all the business unit tests against hibernate-derby in a clean workspace with these changes.

Thanks,
Mitesh


Mitesh Meswani wrote:
Hi,

I am working to port Roller's backend code to use JPA/JDO (see trunk/sandbox/jdobackend). I ran across some code that is not portable across persistence strategies. Attached is a patch to fix that. The patch is from trunk dir based on revision 491960

Following is a summary of changes:
1. src/org/apache/roller/pojos/FolderData.java, src/org/apache/roller/pojos/WeblogCategoryData.java: JPA assumes that relationships are managed by user code and not persistence provider. If we have a one-to-many relationship, if the "many side" is set to point to an instance, the "one side" also needs to add it the collection. For example if we set a FolderData's "parent", the parent should add it to its "childFolders" collection. FolderData and WeblogCategoryData is modified to follow this convention.

2. tests/org/apache/roller/business/PingsTest.java
The test calls AutpoingManager#removeAutoPings(Collection) passing it a collection of unmanged instances. It is modified to remove manged version instead. I have verified that when AutpoingManager#removeAutoPings is called from roller code(PingSetupAction#disableSelected()), the instances are managed

I have successfully run all tests against hibernate-derby with these changes. Please review and check in.

Thanks,
Mitesh




------------------------------------------------------------------------

Index: src/org/apache/roller/pojos/FolderData.java
===================================================================
--- src/org/apache/roller/pojos/FolderData.java (revision 491943)
+++ src/org/apache/roller/pojos/FolderData.java (working copy)
@@ -84,6 +84,15 @@
         } else {
             this.path = parent.getPath() + "/" + name;
         }
+
+        this.parentFolder = parent;
+        // Relationship needs to be maintained from both sides
+        if(parent != null) {
+            // Following triggers this.hascode(). Which is calculated based on 
this.path
+            // It needs to happen after this.path is initialized
+            parent.childFolders.add(this);
+        }
+
     }
Index: src/org/apache/roller/pojos/WeblogCategoryData.java
===================================================================
--- src/org/apache/roller/pojos/WeblogCategoryData.java (revision 491943)
+++ src/org/apache/roller/pojos/WeblogCategoryData.java (working copy)
@@ -71,8 +71,7 @@
         this.image = image;
this.website = website;
-        this.parentCategory = parent;
- +
         // calculate path
         if(parent == null) {
             this.path = "/";
@@ -81,6 +80,15 @@
         } else {
             this.path = parent.getPath() + "/" + name;
         }
+
+        this.parentCategory = parent;
+        // Relationship needs to be maintained from both sides
+        if(parent != null) {
+            // Following triggers this.hascode(). Which is calculated based on 
this.path
+            // It needs to happen after this.path is initialized
+            parent.childCategories.add(this);
+        }
+
     }
Index: tests/org/apache/roller/business/PingsTest.java
===================================================================
--- tests/org/apache/roller/business/PingsTest.java     (revision 491943)
+++ tests/org/apache/roller/business/PingsTest.java     (working copy)
@@ -314,7 +314,9 @@
// remove a collection
         List autoPings = new ArrayList();
+        autoPing2 = mgr.getAutoPing(autoPing2.getId()); //Get managed version 
of autoPing2
         autoPings.add(autoPing2);
+        autoPing3 = mgr.getAutoPing(autoPing3.getId()); //Get managed version 
of autoPing2
         autoPings.add(autoPing3);
         mgr.removeAutoPings(autoPings);
         TestUtils.endSession(true);
Index: src/org/apache/roller/pojos/FolderData.java
===================================================================
--- src/org/apache/roller/pojos/FolderData.java (revision 494690)
+++ src/org/apache/roller/pojos/FolderData.java (working copy)
@@ -84,16 +84,6 @@
         } else {
             this.path = parent.getPath() + "/" + name;
         }
-
-        this.parentFolder = parent;
-        // Relationships need to be maintained from both sides
-        if(parent != null) {
-            // The following triggers this.hashCode(), which is calculated 
-            // based on this.path
-            // It needs to happen after this.path is initialized
-            parent.childFolders.add(this);
-        }
-
     }
     
     
Index: src/org/apache/roller/pojos/WeblogCategoryData.java
===================================================================
--- src/org/apache/roller/pojos/WeblogCategoryData.java (revision 494690)
+++ src/org/apache/roller/pojos/WeblogCategoryData.java (working copy)
@@ -71,6 +71,7 @@
         this.image = image;
         
         this.website = website;
+        this.parentCategory = parent;
 
         // calculate path
         if(parent == null) {
@@ -80,16 +81,6 @@
         } else {
             this.path = parent.getPath() + "/" + name;
         }
-
-        this.parentCategory = parent;
-        // Relationship needs to be maintained from both sides
-        if(parent != null) {
-            // Following triggers this.hashCode(), which is calculated 
-            // based on this.path
-            // It needs to happen after this.path is initialized
-            parent.childCategories.add(this);
-        }
-
     }
     
     

Reply via email to