Bug 103258 - Category.deleteCategoryAndRemap() fails when there are related categories
Summary: Category.deleteCategoryAndRemap() fails when there are related categories
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Web Application Framework
Classification: Retired
Component: other
Version: nightly
Hardware: All
OS: Linux
medium
high
Target Milestone: ---
Assignee: Archit Shah
QA Contact: Jon Orris
URL:
Whiteboard:
Depends On:
Blocks: 100952
TreeView+ depends on / blocked
 
Reported: 2003-08-28 08:17 UTC by Carsten Clasohm
Modified: 2007-04-18 16:57 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2003-12-10 20:41:15 UTC
Embargoed:


Attachments (Terms of Use)
JSP for reproducing the problem (337 bytes, text/plain)
2003-08-28 08:18 UTC, Carsten Clasohm
no flags Details

Description Carsten Clasohm 2003-08-28 08:17:14 UTC
Description of problem:
When calling Category.deleteCategoryAndRemap() for a category to which related
categories have been added with addRelatedCategory(), deletion of the "related
categories" association fails with a "IllegalArgumentException: No such object"
exception.


Version-Release number of selected component (if applicable):
6.0

How reproducible:
Always

Steps to Reproduce:
Replace the two category IDs in the attached JSP with actual values from your
cat_categories table and try to run the JSP.


Actual Results:  
java.lang.IllegalArgumentException: No such object:
[com.arsdigita.categorization.com_arsdigita_categorization_Category:parents::com_arsdigita_categorization_Category:related::Link:{parents=[com.arsdigita.categorization.Category:{id=147}],
related=[com.arsdigita.categorization.Category:{id=165}]}]
	at com.redhat.persistence.Session.fetchPropertyData(Session.java:787)
	at com.redhat.persistence.Session$1.onRole(Session.java:115)
	at com.redhat.persistence.metadata.Role.dispatch(Role.java:92)
	at com.redhat.persistence.Session.get(Session.java:113)
	at com.arsdigita.persistence.DataObjectImpl.get(DataObjectImpl.java:489)
	at com.arsdigita.persistence.DataObjectImpl.get(DataObjectImpl.java:200)
	at com.arsdigita.categorization.Category.deleteCategoryAndRemap(Category.java:923)


Additional info:

The cause for this error is the following while loop, which first deletes the
association and then tries to retrieve attributes from the link object it has
just deleted:

        while (cursor.next()) {
            DataObject link = cursor.getLink();
            remove(RELATED_CATEGORIES, cursor.getDataObject());
            if ("child".equals(link.get("relationType"))) {
                Category category = new Category(cursor.getDataObject());
                parent.addChild(category);
                if (Boolean.TRUE.equals(link.get("isDefault"))) {
                    category.setDefaultParentCategory(parent);
                }
            }
        }

One way to fix this:

        while (cursor.next()) {
            DataObject link = cursor.getLink();
	    String relationType = (String)link.get("relationType");
	    Boolean isDefault = (Boolean)link.get("isDefault");
            remove(RELATED_CATEGORIES, cursor.getDataObject());
            if ("child".equals(relationType)) {
                Category category = new Category(cursor.getDataObject());
                parent.addChild(category);
                if (Boolean.TRUE.equals(isDefault)) {
                    category.setDefaultParentCategory(parent);
                }
            }
        }

Comment 1 Carsten Clasohm 2003-08-28 08:18:47 UTC
Created attachment 94025 [details]
JSP for reproducing the problem

Comment 2 Richard Li 2003-08-28 11:47:07 UTC
Carsten: does your 35415 fix the problem, or does it need to be fixed some other
way?

Comment 3 Carsten Clasohm 2003-08-28 11:53:07 UTC
35415 fixes it.


Comment 4 Jon Orris 2003-12-09 23:37:48 UTC
Has this been integrated onto the Troika branch at all?


Comment 5 Jon Orris 2003-12-10 20:41:15 UTC
Integrated by Archit @35437


Note You need to log in before you can comment on or make changes to this bug.