Loading ...
Sorry, an error occurred while loading the content.

Re: [xml-dbms] newbie query: More than one class mapped to the table

Expand Messages
  • Ronald Bourret
    Sorry to take so long answering. I ve been gone on vacation and business. The short answer: there isn t a useful workaround. (You could disable the check for
    Message 1 of 4 , Jan 13, 2001
    • 0 Attachment
      Sorry to take so long answering. I've been gone on vacation and
      business.

      The short answer: there isn't a useful workaround. (You could disable
      the check for duplicate mappings, but that leads to other problems, as
      you will see below.)

      The longer answer: This is an interesting problem. Up until now, I
      hadn't been convinced of the usefulness of mapping two different element
      types to the same table, but this is a use case that shows this makes a
      lot of sense.

      Unfortunately, XML-DBMS runs into problems with this when transferring
      data from the database to XML. (Transferring data from XML to the
      database is easy.) Specifically, when XML-DBMS retrieves a row from the
      PERSONNEL table, it has no way of determining whether it should create a
      FoundBy element or an AssignedTo element for that row.

      (I realize that XML-DBMS could probably determine this from context in
      the case shown. However, consider the case <!ELEMENT A (B | C)+ > where
      both B and C are mapped to the same table. There is no way to determine
      whether a given row in that table came from a B element or a C element.)

      Any suggestions on how to solve this problem are welcome.

      -- Ron

      Walter Higgins wrote:
      >
      > Hi,
      >
      > I have a problem (not sure if this is the right place to post it) ...
      > I am trying to map more than one class to the one db table. XML-DBMS
      > doesn't allow me to do this so I must be doing something wrong.
      > I was wondering if someone could help.
      >
      > I have the following database scheme...
      >
      > BUG
      > ---
      > BUGID INTEGER (PK)
      > BUGDESC VARCHAR(20)
      > FOUNDBY INTEGER (FK)----------
      > ASSIGNEDTO INTEGER (FK)---------|
      > |
      > PERSONNEL |
      > --------- |
      > PID INTEGER (PK) <--------
      > PNAME VARCHAR(20)
      > PEXT VARCHAR(20)
      >
      > Basically I want to extract the bug description and the name and extension
      > of the person who found the bug and the name and extension of the person
      > the bug is assigned to e.g.
      > <BugList>
      > <Bug Description="a minor bug">
      > <FoundBy Name="Alan" Extension="200"/>
      > <AssignedTo Name="Walter" Extension="143"/>
      > </Bug>
      > </BugList>
      >
      > I was using the following map file but xml-dbms throws the following
      > exception...
      >
      > de.tudarmstadt.ito.xmldbms.InvalidMapException: More than one class mapped
      > to the table: PERSONNEL
      >
      > Is there a workaround ?
      >
      > Many thanks
      >
      > Walter Higgins
      >
      > <?xml version="1.0"?>
      > <!DOCTYPE XMLToDBMS SYSTEM "xmldbms.dtd">
      > <XMLToDBMS Version="1.0">
      > <Maps>
      > <IgnoreRoot>
      > <ElementType Name="BugList"/>
      > <PseudoRoot>
      > <ElementType Name="Bug"/>
      > </PseudoRoot>
      > </IgnoreRoot>
      > <ClassMap>
      > <ElementType Name="Bug"/>
      > <ToClassTable>
      > <Table Name="Result Set"/>
      > </ToClassTable>
      >
      > <!-- Attribute property mappings -->
      > <PropertyMap><Attribute Name="Description"/><ToColumn><Column
      > Name="BUGDESC"/></ToColumn></PropertyMap>
      >
      > <!-- Nested tag relationships -->
      > <RelatedClass KeyInParentTable="Candidate">
      > <ElementType Name="AssignedTo"/>
      > <CandidateKey Generate="No">
      > <Column Name="ASSIGNEDTO"/>
      > </CandidateKey>
      > <ForeignKey>
      > <Column Name="PID"/>
      > </ForeignKey>
      > </RelatedClass>
      >
      > <RelatedClass KeyInParentTable="Candidate">
      > <ElementType Name="FoundBy"/>
      > <CandidateKey Generate="No">
      > <Column Name="ASSIGNEDTO"/>
      > </CandidateKey>
      > <ForeignKey>
      > <Column Name="PID"/>
      > </ForeignKey>
      > </RelatedClass>
      >
      > </ClassMap>
      >
      > <ClassMap>
      > <ElementType Name="AssignedTo"/>
      > <ToClassTable>
      > <Table Name="PERSONNEL"/>
      > </ToClassTable>
      > <!-- Attribute property mappings -->
      > <PropertyMap><Attribute Name="Name"/><ToColumn><Column
      > Name="PNAME"/></ToColumn></PropertyMap>
      > <PropertyMap><Attribute Name="Extension"/><ToColumn><Column
      > Name="PEXT"/></ToColumn></PropertyMap>
      > </ClassMap>
      >
      > <ClassMap>
      > <ElementType Name="FoundBy"/>
      > <ToClassTable>
      > <Table Name="PERSONNEL"/>
      > </ToClassTable>
      > <!-- Attribute property mappings -->
      > <PropertyMap><Attribute Name="Name"/><ToColumn><Column
      > Name="PNAME"/></ToColumn></PropertyMap>
      > <PropertyMap><Attribute Name="Extension"/><ToColumn><Column
      > Name="PEXT"/></ToColumn></PropertyMap>
      > </ClassMap>
      > </Maps>
      > </XMLToDBMS>

      --
      Ronald Bourret
      Programming, Writing, and Training
      XML, Databases, and Schemas
      http://www.rpbourret.com
    • Ronald Bourret
      One other thing about this. I suspect that this problem is strongly related to inheritance -- the relationship shown could be described as there being a common
      Message 2 of 4 , Jan 13, 2001
      • 0 Attachment
        One other thing about this.

        I suspect that this problem is strongly related to inheritance -- the
        relationship shown could be described as there being a common base tyep
        for the FoundBy and AssignedTo elements.

        This raises an interesting question about what happens when inheritance
        is represented in the database by a base class table and an extended
        class table. In the case shown, there wouldn't be any extended class
        tables, since no properties were added during inheritance. So this
        problem is more generic than it first appears.

        It also occurs in one other case I can think of. That is, in XML
        schemas, there is a substitution group mechanism of some sort where you
        can declare that element type x really should be treated the same as
        element type y. This would map exactly to the case shown and raises the
        same sort of problems.

        Again, ideas on how to solve this are appreciated.

        -- Ron

        Ronald Bourret wrote:
        >
        > Sorry to take so long answering. I've been gone on vacation and
        > business.
        >
        > The short answer: there isn't a useful workaround. (You could disable
        > the check for duplicate mappings, but that leads to other problems, as
        > you will see below.)
        >
        > The longer answer: This is an interesting problem. Up until now, I
        > hadn't been convinced of the usefulness of mapping two different element
        > types to the same table, but this is a use case that shows this makes a
        > lot of sense.
        >
        > Unfortunately, XML-DBMS runs into problems with this when transferring
        > data from the database to XML. (Transferring data from XML to the
        > database is easy.) Specifically, when XML-DBMS retrieves a row from the
        > PERSONNEL table, it has no way of determining whether it should create a
        > FoundBy element or an AssignedTo element for that row.
        >
        > (I realize that XML-DBMS could probably determine this from context in
        > the case shown. However, consider the case <!ELEMENT A (B | C)+ > where
        > both B and C are mapped to the same table. There is no way to determine
        > whether a given row in that table came from a B element or a C element.)
        >
        > Any suggestions on how to solve this problem are welcome.
        >
        > -- Ron
        >
        > Walter Higgins wrote:
        > >
        > > Hi,
        > >
        > > I have a problem (not sure if this is the right place to post it) ...
        > > I am trying to map more than one class to the one db table. XML-DBMS
        > > doesn't allow me to do this so I must be doing something wrong.
        > > I was wondering if someone could help.
        > >
        > > I have the following database scheme...
        > >
        > > BUG
        > > ---
        > > BUGID INTEGER (PK)
        > > BUGDESC VARCHAR(20)
        > > FOUNDBY INTEGER (FK)----------
        > > ASSIGNEDTO INTEGER (FK)---------|
        > > |
        > > PERSONNEL |
        > > --------- |
        > > PID INTEGER (PK) <--------
        > > PNAME VARCHAR(20)
        > > PEXT VARCHAR(20)
        > >
        > > Basically I want to extract the bug description and the name and extension
        > > of the person who found the bug and the name and extension of the person
        > > the bug is assigned to e.g.
        > > <BugList>
        > > <Bug Description="a minor bug">
        > > <FoundBy Name="Alan" Extension="200"/>
        > > <AssignedTo Name="Walter" Extension="143"/>
        > > </Bug>
        > > </BugList>
        > >
        > > I was using the following map file but xml-dbms throws the following
        > > exception...
        > >
        > > de.tudarmstadt.ito.xmldbms.InvalidMapException: More than one class mapped
        > > to the table: PERSONNEL
        > >
        > > Is there a workaround ?
        > >
        > > Many thanks
        > >
        > > Walter Higgins
        > >
        > > <?xml version="1.0"?>
        > > <!DOCTYPE XMLToDBMS SYSTEM "xmldbms.dtd">
        > > <XMLToDBMS Version="1.0">
        > > <Maps>
        > > <IgnoreRoot>
        > > <ElementType Name="BugList"/>
        > > <PseudoRoot>
        > > <ElementType Name="Bug"/>
        > > </PseudoRoot>
        > > </IgnoreRoot>
        > > <ClassMap>
        > > <ElementType Name="Bug"/>
        > > <ToClassTable>
        > > <Table Name="Result Set"/>
        > > </ToClassTable>
        > >
        > > <!-- Attribute property mappings -->
        > > <PropertyMap><Attribute Name="Description"/><ToColumn><Column
        > > Name="BUGDESC"/></ToColumn></PropertyMap>
        > >
        > > <!-- Nested tag relationships -->
        > > <RelatedClass KeyInParentTable="Candidate">
        > > <ElementType Name="AssignedTo"/>
        > > <CandidateKey Generate="No">
        > > <Column Name="ASSIGNEDTO"/>
        > > </CandidateKey>
        > > <ForeignKey>
        > > <Column Name="PID"/>
        > > </ForeignKey>
        > > </RelatedClass>
        > >
        > > <RelatedClass KeyInParentTable="Candidate">
        > > <ElementType Name="FoundBy"/>
        > > <CandidateKey Generate="No">
        > > <Column Name="ASSIGNEDTO"/>
        > > </CandidateKey>
        > > <ForeignKey>
        > > <Column Name="PID"/>
        > > </ForeignKey>
        > > </RelatedClass>
        > >
        > > </ClassMap>
        > >
        > > <ClassMap>
        > > <ElementType Name="AssignedTo"/>
        > > <ToClassTable>
        > > <Table Name="PERSONNEL"/>
        > > </ToClassTable>
        > > <!-- Attribute property mappings -->
        > > <PropertyMap><Attribute Name="Name"/><ToColumn><Column
        > > Name="PNAME"/></ToColumn></PropertyMap>
        > > <PropertyMap><Attribute Name="Extension"/><ToColumn><Column
        > > Name="PEXT"/></ToColumn></PropertyMap>
        > > </ClassMap>
        > >
        > > <ClassMap>
        > > <ElementType Name="FoundBy"/>
        > > <ToClassTable>
        > > <Table Name="PERSONNEL"/>
        > > </ToClassTable>
        > > <!-- Attribute property mappings -->
        > > <PropertyMap><Attribute Name="Name"/><ToColumn><Column
        > > Name="PNAME"/></ToColumn></PropertyMap>
        > > <PropertyMap><Attribute Name="Extension"/><ToColumn><Column
        > > Name="PEXT"/></ToColumn></PropertyMap>
        > > </ClassMap>
        > > </Maps>
        > > </XMLToDBMS>
        >
        > --
        > Ronald Bourret
        > Programming, Writing, and Training
        > XML, Databases, and Schemas
        > http://www.rpbourret.com
        >
        > To Post a message, send it to: xml-dbms@...
        >
        > To Unsubscribe, send a blank message to: xml-dbms-unsubscribe@...

        --
        Ronald Bourret
        Programming, Writing, and Training
        XML, Databases, and Schemas
        http://www.rpbourret.com
      Your message has been successfully submitted and would be delivered to recipients shortly.