Re: Hierarchical relationship problems

From: Filip Balas (fbala..mail.com)
Date: Thu Apr 28 2005 - 17:28:44 EDT

  • Next message: Andrus Adamchik: "Re: Hierarchical relationship problems"

    After simplifying the map file to the 3 tables that are causing the
    problem, I get a very reproducible error. The relationship from
    Location to Phone Number allows you to add Phone Numbers to Locations
    but the reverse relationship is not being mapped into the POJO's.
    This results in not being able to link a Location to a Phone Number,
    from the Phone Number class. This results in classes similar to this:

    Location
      addToPhone_numbers(PhoneNumber)
      getPhone_numbers()
      removeFromPhone_numbers()

    PhoneNumber
      getLocation
    MISSING
      setLocation(Location)

    Included are the cayenne, map and node xml files.

    TESTMap.map.xml
    <?xml version="1.0" encoding="utf-8"?>
    <data-map project-version="1.1">
            <property name="defaultPackage" value="test"/>
            <property name="defaultSchema" value="dbo"/>
            <db-entity name="IMV_location_phone_nums" schema="dbo">
                    <db-attribute name="location_id" type="INTEGER" length="10"/>
                    <db-attribute name="phone_id" type="INTEGER" length="10"/>
            </db-entity>
            <db-entity name="IMV_locations" schema="dbo" catalog="GPSForecast">
                    <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
    isMandatory="true" isGenerated="true" length="10"/>
                    <db-attribute name="parent_id" type="INTEGER" length="10"/>
            </db-entity>
            <db-entity name="IMV_phone_numbers" schema="dbo">
                    <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
    isMandatory="true" isGenerated="true" length="10"/>
                    <db-attribute name="phone_num_type_id" type="INTEGER"
    isMandatory="true" length="10"/>
            </db-entity>
            <obj-entity name="Location" className="test.Location"
    dbEntityName="IMV_locations">
            </obj-entity>
            <obj-entity name="PhoneNumber" className="test.PhoneNumber"
    dbEntityName="IMV_phone_numbers">
            </obj-entity>
            <db-relationship name="location" source="IMV_location_phone_nums"
    target="IMV_locations" toMany="false">
                    <db-attribute-pair source="location_id" target="id"/>
            </db-relationship>
            <db-relationship name="phone_nums" source="IMV_location_phone_nums"
    target="IMV_phone_numbers" toMany="false">
                    <db-attribute-pair source="phone_id" target="id"/>
            </db-relationship>
            <db-relationship name="rel_ph_loc" source="IMV_locations"
    target="IMV_location_phone_nums" toMany="true">
                    <db-attribute-pair source="id" target="location_id"/>
            </db-relationship>
            <db-relationship name="rel_ph_loc" source="IMV_phone_numbers"
    target="IMV_location_phone_nums" toMany="false">
                    <db-attribute-pair source="id" target="phone_id"/>
            </db-relationship>
            <obj-relationship name="phone_numbers" source="Location"
    target="PhoneNumber" db-relationship-path="rel_ph_loc.phone_nums"/>
            <obj-relationship name="location" source="PhoneNumber"
    target="Location" db-relationship-path="rel_ph_loc.location"/>
    </data-map>

    TESTNode.driver.xml
    <?xml version="1.0" encoding="utf-8"?>
    <driver project-version="1.1" class="net.sourceforge.jtds.jdbc.Driver">
            <url value="jdbc:jtds:sqlserver://TESTDB:1433/GPSForecast"/>
            <connectionPool min="1" max="5" />
            <login userName="sa" password="password"/>
    </driver>

    cayenne.xml
    <?xml version="1.0" encoding="utf-8"?>
    <domains project-version="1.1">
    <domain name="TEST">
            <map name="TESTMap" location="TESTMap.map.xml"/>

            <node name="TESTNode"
                     datasource="TESTNode.driver.xml"
                     adapter="org.objectstyle.cayenne.dba.sqlserver.SQLServerAdapter"
                     factory="org.objectstyle.cayenne.conf.DriverDataSourceFactory">
                            <map-ref name="TESTMap"/>
             </node>
    </domain>
    </domains>

    Thank you for looking into this matter

    Fil

    On 4/28/05, Filip Balas <fbala..mail.com> wrote:
    > I am getting an inconsistency and I can't figure out if I'm missing
    > something or not.. I think everything looks right but my Employee
    > objectEntity is generating all of the add/set/remove methods but
    > the Location objectEntity is not...addTo/RemoveFrom Phone_numbers
    > is missing?
    > Okay, Andrus can your run this and see what you generate?
    >
    > map.xml
    > ------------------
    > <?xml version="1.0" encoding="utf-8"?>
    > <data-map project-version="1.1">
    > <property name="defaultPackage" value="test"/>
    > <property name="defaultSchema" value="dbo"/>
    > <db-entity name="IMV_employee_phone_nums" schema="dbo">
    > <db-attribute name="employee_id" type="INTEGER" isMandatory="true"
    > length="10"/>
    > <db-attribute name="phone_id" type="INTEGER" isPrimaryKey="true"
    > isMandatory="true" length="10"/>
    > </db-entity>
    > <db-entity name="IMV_employees" schema="dbo">
    > <db-attribute name="GP_id" type="CHAR" isMandatory="true" length="15"/>
    > <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
    > isMandatory="true" isGenerated="true"/>
    > <db-attribute name="title_dept" type="INTEGER" length="10"/>
    > </db-entity>
    > <db-entity name="IMV_location_phone_nums" schema="dbo">
    > <db-attribute name="location_id" type="INTEGER" isMandatory="true"
    > length="10"/>
    > <db-attribute name="phone_id" type="INTEGER" isPrimaryKey="true"
    > isMandatory="true" length="10"/>
    > </db-entity>
    > <db-entity name="IMV_locations" schema="dbo" catalog="GPSForecast">
    > <db-attribute name="description" type="VARCHAR" length="75"/>
    > <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
    > isMandatory="true" isGenerated="true" length="10"/>
    > <db-attribute name="parent_id" type="INTEGER" length="10"/>
    > </db-entity>
    > <db-entity name="IMV_phone_list_admins" schema="dbo">
    > <db-attribute name="employee_id" type="INTEGER" isPrimaryKey="true"
    > isMandatory="true" length="10"/>
    > </db-entity>
    > <db-entity name="IMV_phone_numbers" schema="dbo">
    > <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
    > isMandatory="true" isGenerated="true" length="10"/>
    > <db-attribute name="phone_num_type_id" type="INTEGER"
    > isMandatory="true" length="10"/>
    > <db-attribute name="phone_number" type="VARCHAR" length="50"/>
    > </db-entity>
    > <db-entity name="IMV_phone_types" schema="dbo">
    > <db-attribute name="description" type="VARCHAR" length="75"/>
    > <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
    > isMandatory="true" isGenerated="true" length="10"/>
    > <db-attribute name="type" type="VARCHAR" isMandatory="true" length="25"/>
    > </db-entity>
    > <db-entity name="IMV_titles_depts" schema="dbo">
    > <db-attribute name="description" type="VARCHAR" length="75"/>
    > <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
    > isMandatory="true" isGenerated="true" length="10"/>
    > </db-entity>
    > <obj-entity name="Employee" className="test.Employee"
    > dbEntityName="IMV_employees">
    > </obj-entity>
    > <obj-entity name="Location" className="test.Location"
    > dbEntityName="IMV_locations">
    > <obj-attribute name="_description" type="java.lang.String"
    > db-attribute-path="description"/>
    > </obj-entity>
    > <obj-entity name="PhoneAdmin" className="test.PhoneAdmin"
    > dbEntityName="IMV_phone_list_admins">
    > </obj-entity>
    > <obj-entity name="PhoneNumber" className="test.PhoneNumber"
    > dbEntityName="IMV_phone_numbers">
    > <obj-attribute name="_phone_number" type="java.lang.String"
    > db-attribute-path="phone_number"/>
    > </obj-entity>
    > <obj-entity name="PhoneType" className="test.PhoneType"
    > dbEntityName="IMV_phone_types">
    > <obj-attribute name="_description" type="java.lang.String"
    > db-attribute-path="description"/>
    > <obj-attribute name="_type" type="java.lang.String" db-attribute-path="type"/>
    > </obj-entity>
    > <obj-entity name="Title_OR_Dept" className="test.Title_OR_Dept"
    > dbEntityName="IMV_titles_depts">
    > <obj-attribute name="_description" type="java.lang.String"
    > db-attribute-path="description"/>
    > </obj-entity>
    > <db-relationship name="employee" source="IMV_employee_phone_nums"
    > target="IMV_employees" toMany="false">
    > <db-attribute-pair source="employee_id" target="id"/>
    > </db-relationship>
    > <db-relationship name="phone_numbers"
    > source="IMV_employee_phone_nums" target="IMV_phone_numbers"
    > toDependentPK="true" toMany="false">
    > <db-attribute-pair source="phone_id" target="id"/>
    > </db-relationship>
    > <db-relationship name="admin" source="IMV_employees"
    > target="IMV_phone_list_admins" toDependentPK="true" toMany="false">
    > <db-attribute-pair source="id" target="employee_id"/>
    > </db-relationship>
    > <db-relationship name="rel_ph_emp" source="IMV_employees"
    > target="IMV_employee_phone_nums" toMany="true">
    > <db-attribute-pair source="id" target="employee_id"/>
    > </db-relationship>
    > <db-relationship name="title_deptartment" source="IMV_employees"
    > target="IMV_titles_depts" toMany="false">
    > <db-attribute-pair source="title_dept" target="id"/>
    > </db-relationship>
    > <db-relationship name="location" source="IMV_location_phone_nums"
    > target="IMV_locations" toMany="false">
    > <db-attribute-pair source="location_id" target="id"/>
    > </db-relationship>
    > <db-relationship name="phone_nums" source="IMV_location_phone_nums"
    > target="IMV_phone_numbers" toDependentPK="true" toMany="false">
    > <db-attribute-pair source="phone_id" target="id"/>
    > </db-relationship>
    > <db-relationship name="children" source="IMV_locations"
    > target="IMV_locations" toMany="true">
    > <db-attribute-pair source="id" target="parent_id"/>
    > </db-relationship>
    > <db-relationship name="parent" source="IMV_locations"
    > target="IMV_locations" toMany="false">
    > <db-attribute-pair source="parent_id" target="id"/>
    > </db-relationship>
    > <db-relationship name="rel_ph_loc" source="IMV_locations"
    > target="IMV_location_phone_nums" toMany="true">
    > <db-attribute-pair source="id" target="location_id"/>
    > </db-relationship>
    > <db-relationship name="employee" source="IMV_phone_list_admins"
    > target="IMV_employees" toMany="false">
    > <db-attribute-pair source="employee_id" target="id"/>
    > </db-relationship>
    > <db-relationship name="rel_ph_emp" source="IMV_phone_numbers"
    > target="IMV_employee_phone_nums" toMany="false">
    > <db-attribute-pair source="id" target="phone_id"/>
    > </db-relationship>
    > <db-relationship name="rel_ph_loc" source="IMV_phone_numbers"
    > target="IMV_location_phone_nums" toMany="false">
    > <db-attribute-pair source="id" target="phone_id"/>
    > </db-relationship>
    > <db-relationship name="type" source="IMV_phone_numbers"
    > target="IMV_phone_types" toMany="false">
    > <db-attribute-pair source="phone_num_type_id" target="id"/>
    > </db-relationship>
    > <db-relationship name="phone_numbers" source="IMV_phone_types"
    > target="IMV_phone_numbers" toMany="true">
    > <db-attribute-pair source="id" target="phone_num_type_id"/>
    > </db-relationship>
    > <db-relationship name="employees" source="IMV_titles_depts"
    > target="IMV_employees" toMany="true">
    > <db-attribute-pair source="id" target="title_dept"/>
    > </db-relationship>
    > <obj-relationship name="admin" source="Employee" target="PhoneAdmin"
    > db-relationship-path="admin"/>
    > <obj-relationship name="locations" source="Employee"
    > target="Location"
    > db-relationship-path="rel_ph_emp.phone_numbers.rel_ph_loc.location"/>
    > <obj-relationship name="phone_numbers" source="Employee"
    > target="PhoneNumber" db-relationship-path="rel_ph_emp.phone_numbers"/>
    > <obj-relationship name="title_dept" source="Employee"
    > target="Title_OR_Dept" db-relationship-path="title_deptartment"/>
    > <obj-relationship name="children" source="Location" target="Location"
    > deleteRule="Cascade" db-relationship-path="children"/>
    > <obj-relationship name="employees" source="Location"
    > target="Employee"
    > db-relationship-path="rel_ph_loc.phone_nums.rel_ph_emp.employee"/>
    > <obj-relationship name="parent" source="Location" target="Location"
    > db-relationship-path="parent"/>
    > <obj-relationship name="phone_numbers" source="Location"
    > target="PhoneNumber" db-relationship-path="rel_ph_loc.phone_nums"/>
    > <obj-relationship name="employee" source="PhoneAdmin"
    > target="Employee" db-relationship-path="employee"/>
    > <obj-relationship name="employee" source="PhoneNumber"
    > target="Employee" db-relationship-path="rel_ph_emp.employee"/>
    > <obj-relationship name="location" source="PhoneNumber"
    > target="Location" db-relationship-path="rel_ph_loc.location"/>
    > <obj-relationship name="type" source="PhoneNumber" target="PhoneType"
    > db-relationship-path="type"/>
    > <obj-relationship name="phone_numbers" source="PhoneType"
    > target="PhoneNumber" db-relationship-path="phone_numbers"/>
    > <obj-relationship name="employees" source="Title_OR_Dept"
    > target="Employee" db-relationship-path="employees"/>
    > </data-map>
    >
    > I appologize in advance if I have missed something...
    > Filip
    >
    > On 4/28/05, Filip Balas <fbala..mail.com> wrote:
    > > I am going to try remodeling the entire application by hand
    > > from scratch (grrrr...). I used the reengineer feature, which
    > > I think may be what is causing the problem.
    > >
    > > Filip
    > >
    > > On 4/28/05, Filip Balas <fbala..mail.com> wrote:
    > > > I tried manually inserting the code to setParent, addTo/RemoveFrom
    > > > children (I used the code from the isolated table that worked as a
    > > > template) but it does not work. Cayenne will not set the parent even
    > > > though it does not throw any exceptions... I am puzzled.
    > > >
    > > > Filip
    > > >
    > > >
    > > > On 4/28/05, Filip Balas <fbala..mail.com> wrote:
    > > > > Interesting... I have reproduced your results on an isolated
    > > > > table. However, my real scenario has relationships to other
    > > > > tables and other dataMaps so other than that it is identical.
    > > > > Except for the fact that it does not generate the proper
    > > > > add/set/remove methods. Have you seen this before?
    > > > >
    > > > > Filip
    > > > >
    > > > > On 4/27/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
    > > > > > Flattened relationships are those that span more than one
    > > > > > DbRelationship. You don't have them in the mapping below, but you used
    > > > > > to have them in the mapping that you posted here before...
    > > > > >
    > > > > > Anyway, I took your mapping and successfully generated classes with all
    > > > > > normal "set/add/remove" methods... So back to my initial advise - make
    > > > > > sure that you are generating classes from the DataMap below and not
    > > > > > some old copy.
    > > > > >
    > > > > > Andrus
    > > > > >
    > > > > > On Apr 27, 2005, at 6:44 PM, Filip Balas wrote:
    > > > > > > Hi Andrus,
    > > > > > >
    > > > > > > Here is what I'm working with:
    > > > > > >
    > > > > > > <obj-relationship name="children" source="Location" target="Location"
    > > > > > > deleteRule="Cascade" db-relationship-path="rel_children"/>
    > > > > > >
    > > > > > > <obj-relationship name="parent" source="Location" target="Location"
    > > > > > > db-relationship-path="rel_parent"/>
    > > > > > >
    > > > > > > <db-relationship name="rel_children" source="IMV_locations"
    > > > > > > target="IMV_locations" toMany="true">
    > > > > > > <db-attribute-pair source="id" target="parent_id"/>
    > > > > > > </db-relationship>
    > > > > > >
    > > > > > > <db-relationship name="rel_parent" source="IMV_locations"
    > > > > > > target="IMV_locations" toDependentPK="true" toMany="false">
    > > > > > > <db-attribute-pair source="parent_id" target="id"/>
    > > > > > > </db-relationship>
    > > > > > >
    > > > > > > <obj-entity name="Location"
    > > > > > > className="com.imvprojects.phoneList.data.Location"
    > > > > > > dbEntityName="IMV_locations">
    > > > > > > <obj-attribute name="_description" type="java.lang.String"
    > > > > > > db-attribute-path="description"/>
    > > > > > > </obj-entity>
    > > > > > >
    > > > > > > <db-entity name="IMV_locations" schema="dbo" catalog="GPSForecast">
    > > > > > > <db-attribute name="description" type="VARCHAR" length="75"/>
    > > > > > > <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
    > > > > > > isMandatory="true" isGenerated="true" length="10"/>
    > > > > > > <db-attribute name="parent_id" type="INTEGER" length="10"/>
    > > > > > > </db-entity>
    > > > > > >
    > > > > > > I'm not sure what you mean by flattened relationships?
    > > > > > > Do you mean the fact that I am using only one table to
    > > > > > > represent the relationship? Should I be breaking this out?
    > > > > > > I have another relationship where I have a 1:n relationship
    > > > > > > which I have represented in a seperate table (for reasons
    > > > > > > which are not relevent to the discussion) and this class
    > > > > > > has all of the appropriate accessors.
    > > > > > >
    > > > > > > Thanks,
    > > > > > > Filip
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > > On 4/27/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
    > > > > > >> Doublecheck that you cleared those bogus flattened relationships.
    > > > > > >>
    > > > > > >> Read-only relationships are usually generated for all flattened
    > > > > > >> relationships that Cayenne treats are non-updateable (i.e. all except
    > > > > > >> m:n
    > > > > > >> with a single join table). I suspect this is the cause of the problem.
    > > > > > >>
    > > > > > >> Andrus
    > > > > > >>
    > > > > > >>
    > > > > > >>> I didn't notice this before but it appears cayenne
    > > > > > >>> did not generate modifiers for the hierarchical class?
    > > > > > >>>
    > > > > > >>> What I mean is this:
    > > > > > >>>
    > > > > > >>> I HAVE:
    > > > > > >>> Location getParent()
    > > > > > >>> List getChildren();
    > > > > > >>>
    > > > > > >>> I am MISSING:
    > > > > > >>> setParent(Location)
    > > > > > >>> addToChildren(Location)
    > > > > > >>> removeFromChildren(Location)
    > > > > > >>>
    > > > > > >>> I have checked to make sure I didn't inadvertantly
    > > > > > >>> make the entity read-only. Any suggestions?
    > > > > > >>>
    > > > > > >>> Thanks,
    > > > > > >>> Filip
    > > > > > >>>
    > > > > > >>>
    > > > > > >>> On 4/25/05, Filip Balas <fbala..mail.com> wrote:
    > > > > > >>>> Just a quick update so that no one wastes anymore
    > > > > > >>>> time on this other than me. It appears that with the
    > > > > > >>>> clean test, cayenne handles everything just fine.
    > > > > > >>>>
    > > > > > >>>> There must be something else in how I've used the
    > > > > > >>>> modeler or set up the relationships in the database
    > > > > > >>>> that is causing this to happen.
    > > > > > >>>>
    > > > > > >>>> Thanks for your input Andrus, just know that there is
    > > > > > >>>> a test case for this was motivation enough to prove
    > > > > > >>>> myself wrong.
    > > > > > >>>>
    > > > > > >>>> Cheers,
    > > > > > >>>> Filip
    > > > > > >>>>
    > > > > > >>>>
    > > > > > >>>> On 4/25/05, Filip Balas <fbala..mail.com> wrote:
    > > > > > >>>>> Hmmm, okay I don't like to blame someone else's code
    > > > > > >>>>> unless I'm 100% sure. Later today I will set up a purely
    > > > > > >>>>> clean test (seperate table, seperate map, sperate test class). If
    > > > > > >>>> this doesn't work I'll submit a bug...
    > > > > > >>>>>
    > > > > > >>>>> Thanks again,
    > > > > > >>>>> Filip
    > > > > > >>>>>
    > > > > > >>>>> On 4/25/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
    > > > > > >>>>>> I am still dubious that this is Cayenne problem as we have test
    > > > > > >>>> cases that cover this situation. So I recommend doublechecking
    > > > > > >>>> that you don't have your old incorrect DataMap sitting somewhere
    > > > > > >>>> in the classpath, and also check if it works with Cayenne 1.1.1
    > > > > > >>>> (unless your code depends heavily on 1.2 API making this
    > > > > > >>>> impossible).
    > > > > > >>>>>>
    > > > > > >>>>>> If it still doesn't work, please submit a bug report containing
    > > > > > >>>> DataMap XML file and a code snippet that trigers this fetch.
    > > > > > >>>>>>
    > > > > > >>>>>> Andrus
    > > > > > >>>>>>
    > > > > > >>>>>>
    > > > > > >>>>>>> I'm on the bleeding edge (could be why I'm having the
    > > > > > >>>>>>> problem) cayenne 1.2M3.
    > > > > > >>>>>>>
    > > > > > >>>>>>> Filip
    > > > > > >>>>>>>
    > > > > > >>>>>>>
    > > > > > >>>>>>> On 4/25/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
    > > > > > >>>>>>>> You shouldn't have to do anything special. Cayenne (including
    > > > > > >>>> the Modeler) works fine with simple parent-child hierarchies.
    > > > > > >>>> For "children" I expect the generated query to look even
    > > > > > >>>> simpler:
    > > > > > >>>>>>>>
    > > > > > >>>>>>>> SELECT t0.description, t0.id, t0.parent_id
    > > > > > >>>>>>>> FROM dbo.IMV_locations t0, dbo.IMV_locations t1
    > > > > > >>>>>>>> WHERE t0.parent_id = ? [bind: 1]
    > > > > > >>>>>>>>
    > > > > > >>>>>>>> So ... What version of Cayenne do you have? There was a bug
    > > > > > >>>> long time ago that messed it up, but I am fairly sure it is
    > > > > > >>>> fixed in 1.1 final and 1.1.1 releases.
    > > > > > >>>>>>>>
    > > > > > >>>>>>>> Andrus
    > > > > > >>>>>>>>
    > > > > > >>>>>>>>
    > > > > > >>>>>>>>> Hi Andrus,
    > > > > > >>>>>>>>>
    > > > > > >>>>>>>>> Yes that makes perfect sense. I didn't catch that error, I
    > > > > > >>>> just
    > > > > > >>>>>>>> assumed the modeler would generate the right xml when
    > > > > > >>>>>>>>> I selected the proper source and target.
    > > > > > >>>>>>>>>
    > > > > > >>>>>>>>> However, even when I corrected the xml manually to your
    > > > > > >>>> suggestion, I still have the following statement generated by
    > > > > > >>>> cayenne:
    > > > > > >>>>>>>>>
    > > > > > >>>>>>>>> SELECT t0.description, t0.id, t0.parent_id
    > > > > > >>>>>>>>> FROM dbo.IMV_locations t0, dbo.IMV_locations t1
    > > > > > >>>>>>>>> WHERE t0.parent_id = t1.id AND (t1.parent_id = ?) [bind: 1]
    > > > > > >>>>>>>>>
    > > > > > >>>>>>>>> I need it to read:
    > > > > > >>>>>>>>>
    > > > > > >>>>>>>>> SELECT t0.description, t0.id, t0.parent_id
    > > > > > >>>>>>>>> FROM dbo.IMV_locations t0, dbo.IMV_locations t1
    > > > > > >>>>>>>>> WHERE t0.parent_id = t1.id AND (t1.id = ?) [bind: 1]
    > > > > > >>>>>>>>>
    > > > > > >>>>>>>>> In another spot in my code I have a hierarchy set up but it
    > > > > > >>>> is a many to many (map, not tree) and cayenne seems
    > > > > > >>>>>>>>> to deal with that beautifully. To achieve this I have an
    > > > > > >>>>>>>> intermediate table that maps locations to one another. Will I
    > > > > > >>>> have to add
    > > > > > >>>>>>>>> this extra table with a one-To-one constraint to ensure a
    > > > > > >>>> tree
    > > > > > >>>>>>>> structure and not a map?
    > > > > > >>>>>>>>>
    > > > > > >>>>>>>>> Thanks to all who have answered.
    > > > > > >>>>>>>>> Your help is greatly appreciated.
    > > > > > >>>>>>>>> Filip
    > > > > > >>>>>>>>>
    > > > > > >>>>>>>>>
    > > > > > >>>>>>>>>
    > > > > > >>>>>>>>> On 4/24/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
    > > > > > >>>>>>>>>> Hi Filip,
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>>> <obj-relationship name="children" source="Location"
    > > > > > >>>>>>>>>> target="Location" deleteRule="Cascade"
    > > > > > >>>>>>>>>>> db-relationship-path="rel_children.rel_children"/>
    > > > > > >>>>>>>>>>>
    > > > > > >>>>>>>>>>> <obj-relationship name="parent" source="Location"
    > > > > > >>>>>>>> target="Location"
    > > > > > >>>>>>>>>> db-relationship-path="rel_parent.rel_parent"/>
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>> The way relationships above are mapped you'll be getting
    > > > > > >>>>>>>> GRANDchildren and GRANDparents. Is this really what you want?
    > > > > > >>>> The query you quote seems correct (for grandchildren). What I
    > > > > > >>>> mean is that
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>>> SELECT t0.description, t0.id, t0.parent_id
    > > > > > >>>>>>>>>>> FROM dbo.IMV_locations t0, dbo.IMV_locations t1
    > > > > > >>>>>>>>>>> WHERE t0.parent_id = t1.id AND (t1.parent_id = ?) [bind:
    > > > > > >>>> 1]
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>> is a short form for
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>> SELECT t0.description, t0.id, t0.parent_id
    > > > > > >>>>>>>>>> FROM dbo.IMV_locations t0, dbo.IMV_locations t1,
    > > > > > >>>> dbo.IMV_locations
    > > > > > >>>>>>>> t2 WHERE t0.parent_id = t1.id AND t1.parent_id = t2.id AND
    > > > > > >>>> t2.id > > > >> ? [bind: 1]
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>> (see an extra join)... If you need direct children, then you
    > > > > > >>>> need
    > > > > > >>>>>>>> to remove the last component in the obj-relationship path. The
    > > > > > >>>> resulting mapping should look like this:
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>> <obj-relationship name="children" source="Location"
    > > > > > >>>>>>>> target="Location" deleteRule="Cascade"
    > > > > > >>>>>>>>>> db-relationship-path="rel_children"/>
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>> <obj-relationship name="parent" source="Location"
    > > > > > >>>> target="Location"
    > > > > > >>>>>>>> db-relationship-path="rel_parent"/>
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>> I hope I understood your requirements correctly...
    > > > > > >>>>>>>>>>
    > > > > > >>>>>>>>>> Andrus



    This archive was generated by hypermail 2.0.0 : Thu Apr 28 2005 - 17:28:49 EDT