Why is a refetchObject required

From: Steve Wells (stwell..wnmail.net)
Date: Mon Mar 22 2004 - 21:47:25 EST

  • Next message: Andrus Adamchik: "Re: Why is a refetchObject required"

    Hi,

    Using M4 I have a relationship between an Org and a State (as in area of
    a country). An Org has a State.
    Org is defined (simply) as:
    id integer
    name varchar
    state_id integer

    State is:
    id integer
    name varchar

    With a relationship:
    toState linking Org.state_id -> State.id (1:m)

    When I have loaded an Org and call its getToState(), i get a row but the
    State returned is hollow (this is done from JSP/struts).

    I then created a method of Org called getStateName(), same thing:
    State state = this.getToState();
    return state.getName(); // returns null

    So I did:
    State state = this.getToState();
    state = (State)dataContext.refetchObject(state.getObjectId());
    return state.getName(); // returns something, object no longer hollow.

    I would expect to not have to do this.

    below is snippets from my datamap.xml, sorry to bore you with this :)

    <db-entity name="org" catalog="xxx">
            <db-attribute name="full_name" type="VARCHAR" length="100"/>
            <db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="11"/>
            <db-attribute name="state_id" type="INTEGER" isMandatory="true" length="11"/>
    </db-entity>

    <db-entity name="state">
            <db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
            <db-attribute name="name" type="VARCHAR" isMandatory="true" length="3"/>
    </db-entity>

    <obj-entity name="Org" className="xxx.xxx.Org" dbEntityName="org"
    superClassName="asn.lgaq.lgo.reg.data.LGODataObj">
            <obj-attribute name="name" type="java.lang.String" db-attribute-path="full_name"/>
            <obj-attribute name="state_id" type="java.lang.String" db-attribute-path="street_addr_state"/>
    </obj-entity>

    <obj-entity name="State" className="xxx.xxx.StateList"
    dbEntityName="state">
            <obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
    </obj-entity>

    <db-relationship name="toOrgState" source="state" target="org"
    toDependentPK="false" toMany="true">
            <db-attribute-pair source="id" target="state_id"/>
    </db-relationship>

    <db-relationship name="toState" source="org" target="state"
    toDependentPK="false" toMany="false">
            <db-attribute-pair source="state_id" target="id"/>
    </db-relationship>

    <obj-relationship name="toOrgState" source="State" target="Org"
    toMany="true">
            <db-relationship-ref source="state" target="org" name="toOrgState"/>
    </obj-relationship>

    <obj-relationship name="toState" source="Org" target="State"
    toMany="false">
            <db-relationship-ref source="org" target="state" name="toState"/>
    </obj-relationship>

    Also do we need to define the reverse relationsip in 1.1 M4 ?

    Thanks,

    Steve

    -- 
    http://www.fastmail.fm - Access all of your messages and folders
                              wherever you are
    



    This archive was generated by hypermail 2.0.0 : Mon Mar 22 2004 - 21:52:47 EST