Hi, I am trying to get a many-many join working and I am running into a
java.lang.StackOverflowError. 

I have two Objects: Charity and Category. I want the Charity Object to
include a Vector of the Categories to which it belongs and vice versa.
I have tried mimicing the code in both src/examples/jdo and
src/test/jdo, but both cases create circular loops that seem like they
are loading my whole DB. 

We have over 5000 charities in over 100 categories, so that would
explain the StackOverflow. Is there any way to prevent this? 
 
The stack trace, log output, java code and mapping files are all
included below. Any help would be appreciated. 

-August

Stack Trace: 

java.lang.StackOverflowError
        at org.exolab.castor.mapping.loader.FieldHandlerImpl.getValue(Unknown
Source)
        at org.exolab.castor.xml.FieldValidator.validate(Unknown Source)
        at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(Unknown
Source)
        at org.exolab.castor.xml.Validator.validate(Unknown Source)
        at org.exolab.castor.xml.FieldValidator.validate(Unknown Source)
        at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(Unknown
Source)
        at org.exolab.castor.xml.Validator.validate(Unknown Source)
... (* several thousand)


Log Output: 

[justgive] SELECT
"charities"."charityid","charities"."sourceid","charities"."charityname","charities"."charitycode","charities"."haschapters","charities"."mission","charities"."url","charities"."address","charities"."city","charities"."state","charities"."zip","charities"."phone","charities"."keywords","charities"."income","charities"."totalexpenses","charities"."programexpenses","charities"."expenseratio","charities"."yearreported","charities"."yearfounded","charitycategorynodes"."categoryid"
FROM "charities" LEFT OUTER JOIN "charitycategorynodes" ON
"charities"."charityid"="charitycategorynodes"."charityid" WHERE
("charities"."charityid" = ?)
[justgive] Castor: Loading org.justgive.model.Charity (3)
[justgive] Castor: Loading org.justgive.model.Charity (4)
[justgive] Castor: Loading org.justgive.model.Charity (203)
[justgive] Castor: Loading org.justgive.model.Charity (247)
[justgive] Castor: Loading org.justgive.model.Charity (402)
[justgive] Castor: Loading org.justgive.model.Charity (482)
[justgive] Castor: Loading org.justgive.model.Charity (12)
[justgive] Castor: Loading org.justgive.model.Charity (16)
[justgive] Castor: Loading org.justgive.model.Charity (22)
[justgive] Castor: Loading org.justgive.model.Category (65)
[justgive] Castor: Loading org.justgive.model.Charity (80)
[justgive] Castor: Loading org.justgive.model.Charity (81)
[justgive] Castor: Loading org.justgive.model.Charity (5)
[justgive] Castor: Loading org.justgive.model.Charity (65)
[justgive] Castor: Loading org.justgive.model.Charity (85)
[justgive] Castor: Loading org.justgive.model.Charity (204)
[justgive] Castor: Loading org.justgive.model.Charity (120)
[justgive] Castor: Loading org.justgive.model.Charity (288)
[justgive] Castor: Loading org.justgive.model.Charity (47)
[justgive] Castor: Loading org.justgive.model.Charity (336)
[justgive] Castor: Loading org.justgive.model.Charity (489)
[justgive] Castor: Loading org.justgive.model.Charity (512)
[justgive] Castor: Loading org.justgive.model.Charity (535)
[justgive] Castor: Loading org.justgive.model.Charity (899)
[justgive] Castor: Loading org.justgive.model.Charity (931)
[justgive] Castor: Loading org.justgive.model.Category (123)
[justgive] Castor: Loading org.justgive.model.Charity (143)
[justgive] Castor: Loading org.justgive.model.Charity (197)
[justgive] Castor: Loading org.justgive.model.Charity (255)
[justgive] Castor: Loading org.justgive.model.Charity (266)
[justgive] Castor: Loading org.justgive.model.Charity (289)
[justgive] Castor: Loading org.justgive.model.Charity (291)
[justgive] Castor: Loading org.justgive.model.Charity (339)
[justgive] Castor: Loading org.justgive.model.Charity (354)
... (* several thousand)


Charity.java: 

package org.justgive.model;

import java.math.BigDecimal;
import java.util.Vector;

public class Charity {

    //members
    private Integer id;
    private Integer sourceId;
    private String name;
    private String code;
    private Boolean hasChapters;
    private String mission;
    private String url;
    private String address;
    private String city;
    private String state;
    private String zip;
    private String phone;
    private String keywords;
    private BigDecimal income;
    private BigDecimal expenses;
    private BigDecimal programExpenses;
    private Integer expenseRatio;
    private Integer yearReported;
    private Integer yearFounded;

    private Vector categories = new Vector();

    /**
     * Default null constructor
     */
    public Charity() {
        //nada
    }

    //GETTERS AND SETTERS
    public void setId(Integer newValue) {
        id = newValue;
    }

    public Integer getId() {
        return id;
    }

    public void setSourceId(Integer newValue) {
        sourceId = newValue;
    }

    public Integer getSourceId() {
        return sourceId;
    }

    public void setName(String newValue) {
        name = newValue;
    }

    public String getName() {
        return name;
    }

    public void setCode(String newValue) {
        code = newValue;
    }

    public String getCode() {
        return code;
    }

    public void setHasChapters(Boolean newValue) {
        hasChapters = newValue;
    }

    public Boolean getHasChapters() {
        return hasChapters;
    }

    public void setMission(String newValue) {
        mission = newValue;
    }

    public String getMission() {
        return mission;
    }

    public void setUrl(String newValue) {
        url = newValue;
    }

    public String getUrl() {
        return url;
    }

    public void setAddress(String newValue) {
        address = newValue;
    }

    public String getAddress() {
        return address;
    }

    public void setCity(String newValue) {
        city = newValue;
    }

    public String getCity() {
        return city;
    }

    public void setState(String newValue) {
        state = newValue;
    }

    public String getState() {
        return state;
    }

    public void setZip(String newValue) {
        zip = newValue;
    }

    public String getZip() {
        return zip;
    }

    public void setPhone(String newValue) {
        phone = newValue;
    }

    public String getPhone() {
        return phone;
    }

    public void setKeywords(String newValue) {
        keywords = newValue;
    }

    public String getKeywords() {
        return keywords;
    }

    public void setIncome(BigDecimal newValue) {
        income = newValue;
    }

    public BigDecimal getIncome() {
        return income;
    }

    public void setExpenses(BigDecimal newValue) {
        expenses = newValue;
    }

    public BigDecimal getExpenses() {
        return expenses;
    }

    public void setProgramExpenses(BigDecimal newValue) {
        programExpenses = newValue;
    }

    public BigDecimal getProgramExpenses() {
        return programExpenses;
    }

    public void setExpenseRatio(Integer newValue) {
        expenseRatio = newValue;
    }

    public Integer getExpenseRatio() {
        return expenseRatio;
    }

    public void setYearReported(Integer newValue) {
        yearReported = newValue;
    }

    public Integer getYearReported() {
        return yearReported;
    }

    public void setYearFounded(Integer newValue) {
        yearFounded = newValue;
    }

    public Integer getYearFounded() {
        return yearFounded;
    }

    public Vector getCategories() {
        return categories;
    }

    public void setCategories(Vector newValue) {
        categories = newValue;
    }

    /*
    //example of style from src/examples/jdo
    public void addCategories( Category category ) {
        if ( !categories.contains( category ) ) {
            categories.addElement( category );
            category.addCharities( this );
        }
    }
    */



}



Category.java: 

package org.justgive.model;

import java.util.Vector;
import java.util.Enumeration;

public class Category {

    //mambers
    private Integer categoryId;
    private String name;
    //    private Integer parentId;
    private String includePage;

    private Vector charities = new Vector();

    /**
     * Default null constructor
     */
    public Category() {
        //nada
    }


    //GETTERS AND SETTERS
    public void setCategoryId(Integer newValue) {
        categoryId = newValue;
    }

    public Integer getCategoryId() {
        return categoryId;
    }
    /*
    public void setParentId(Integer newValue) {
        parentId = newValue;
    }

    public Integer getParentId() {
        return parentId;
    }
    */
    public void setName(String newValue) {
        name = newValue;
    }

    public String getName() {
        return name;
    }

    public void setIncludePage(String newValue) {
        includePage = newValue;
    }

    public String getIncludePage() {
        return includePage;
    }

    
    public Vector getCharities() {
        return charities;
    }
    
    public void setCharities(Vector newValue) {
        charities = newValue;
    }

    /*
    public void addCharities(Charity charity) {
        if ( !charities.contains( charity ) ) {
            charities.addElement( charity );
            charity.addCategories( this );
        }
    }
    */
    
}

mapping.xml: 

<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version
1.0//EN"
                           "http://castor.exolab.org/mapping.dtd";>
<mapping>

  <!-- Mapping for Category -->
  <class name="org.justgive.model.Category" identity="categoryId">
      <description>Models a single category</description>
      <map-to table="charitycategories" xml="category" />
      <field name="categoryId" type="integer" >
          <sql name="categoryid" type="integer"/>
          <bind-xml name="id" node="element"/>
      </field>
      <field name="name" type="string" >
          <sql name="categoryname" type="varchar"/>
          <bind-xml name="name" node="element"/>
      </field>
      <field name="includePage" type="string" >
          <sql name="pagename" type="varchar"/>
          <bind-xml name="includePage" node="element"/>
      </field>
      <!-- many-many relationship with charities -->
      <field name="charities" type="org.justgive.model.Charity"
required="true" collection="vector">
          <sql name="charityid" many-table="charitycategorynodes"
many-key="categoryid" />
          <xml name="charity" node="element" />
      </field>
  </class>

  <!-- Mapping for Charity -->
  <class name="org.justgive.model.Charity" identity="id">
      <description>Models a single charity</description>
      <map-to table="charities" xml="charity" />
      <field name="id" type="integer" >
          <sql name="charityid" type="integer"/>
          <bind-xml name="id" node="element"/>
      </field>
      <field name="sourceId" type="integer" >
          <sql name="sourceid" type="integer"/>
          <bind-xml name="sourceId" node="element"/>
      </field>
      <field name="name" type="string" >
          <sql name="charityname" type="varchar"/>
          <bind-xml name="name" node="element"/>
      </field>
      <field name="code" type="string" >
          <sql name="charitycode" type="varchar"/>
          <bind-xml name="code" node="element"/>
      </field>
      <field name="hasChapters" type="boolean" >
          <sql name="haschapters" type="bit"/>
          <bind-xml name="hasChapters" node="element"/>
      </field>
      <field name="mission" type="string" >
          <sql name="mission" type="varchar"/>
          <bind-xml name="mission" node="element"/>
      </field>
      <field name="url" type="string" >
          <sql name="url" type="varchar"/>
          <bind-xml name="url" node="element"/>
      </field>
      <field name="address" type="string" >
          <sql name="address" type="varchar"/>
          <bind-xml name="address" node="element"/>
      </field>
      <field name="city" type="string" >
          <sql name="city" type="varchar"/>
          <bind-xml name="city" node="element"/>
      </field>
      <field name="state" type="string" >
          <sql name="state" type="varchar"/>
          <bind-xml name="state" node="element"/>
      </field>
      <field name="zip" type="string" >
          <sql name="zip" type="varchar"/>
          <bind-xml name="zip" node="element"/>
      </field>
      <field name="phone" type="string" >
          <sql name="phone" type="varchar"/>
          <bind-xml name="phone" node="element"/>
      </field>
      <field name="keywords" type="string" >
          <sql name="keywords" type="varchar"/>
          <bind-xml name="keywords" node="element"/>
      </field>
      <field name="income" type="big-decimal" >
          <sql name="income" type="numeric"/>
          <bind-xml name="income" node="element"/>
      </field>
      <field name="expenses" type="big-decimal" >
          <sql name="totalexpenses" type="numeric"/>
          <bind-xml name="expenses" node="element"/>
      </field>
      <field name="programExpenses" type="big-decimal" >
          <sql name="programexpenses" type="numeric"/>
          <bind-xml name="programExpenses" node="element"/>
      </field>
      <field name="expenseRatio" type="integer" >
          <sql name="expenseratio" type="integer"/>
          <bind-xml name="expenseRatio" node="element"/>
      </field>
      <field name="yearReported" type="integer" >
          <sql name="yearreported" type="integer"/>
          <bind-xml name="yearReported" node="element"/>
      </field>
      <field name="yearFounded" type="integer" >
          <sql name="yearfounded" type="integer"/>
          <bind-xml name="yearFounded" node="element"/>
      </field>
      <!-- many-many relationship with categories -->
      <field name="categories" type="org.justgive.model.Category"
required="true" collection="vector">
          <sql name="categoryid" many-table="charitycategorynodes"
many-key="charityid" />
          <xml name="category" node="element" />
      </field>
  </class>



</mapping>


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to