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

Re: [xml-dbms] foreign key / XMLNameChecker error

Expand Messages
  • Ronald Bourret
    Hello, First, I m sorry it took so long to reply. I had a deadline last week that took longer than expected and another job came up unexpectedly. I tried to
    Message 1 of 2 , Nov 6, 2006
      Hello,

      First, I'm sorry it took so long to reply. I had a deadline last week
      that took longer than expected and another job came up unexpectedly.

      I tried to reproduce your problem here and failed -- MapManager worked
      fine for me. (The output map is listed below.)

      I then looked at the code in XMLNameChecker to see if there were any
      obvious problems. The only thing out of the ordinary with your tables is
      that they both have a column named created. This causes a conflict, as
      the basic algorithm in XML-DBMS is to set the element type name to the
      column name. However, XML-DBMS also recognizes the potential for
      conflict and will resolve it -- in your case, by prepending the table
      name to created to create a unique name.

      So I'm not sure where the problem lies. My guess is that the problem is
      that a null String is being passed to XMLNameChecker.checkCharacters and
      that it throws an exception in the first line (oldName =
      name.toCharArray();). You can check this with a debugger or by adding a
      simple System.out.println("got here"); statement.

      What is not clear is where this null is coming from. There are two calls
      to checkCharacters in the private checkName function. Again, you can
      check which one is causing the problem with a debugger or println call.
      Note that the second call is only executed once -- when the second
      created column is encountered.

      The final place to look is in MapFactory_Database.getElementTypeName.
      Adding the following code before the call to
      checker.checkElementTypeName will show you which table/column is causing
      the error:

      System.out.println("table: " + (prefixes[0] == null) ? "null"
      :prefixes[0]);
      System.out.println("schema: " +(prefixes[1] == null) ? "null"
      :prefixes[1]);
      System.out.println("catalog: " + (prefixes[2] == null) ? "null"
      :prefixes[2]);
      System.out.println("database: " + (prefixes[3] == null) ? "null"
      :prefixes[3]);
      String colname = column.getName();
      System.out.println("column: " + (colname == null) ? "null" : colname);

      One final note. The reason that commenting out the foreign key statement
      works is that there is no key for MapManager to follow. This potentially
      lends credence to the idea that the two created columns are causing a
      problem, but it also suggests another possibility.

      Can you check if your JDBC driver supports
      DatabaseMetaData.getExportedKeys? This method is called to find the link
      between your two tables by following the primary key of the
      msms_pipeline_analysis table. If it isn't supported, or if support is
      only partial, it's possible that a null is being introduced somewhere.

      Hope this helps,

      -- Ron

      Generated map document
      ----------------------
      <?xml version='1.0' encoding="Cp1252" ?>
      <!DOCTYPE XMLToDBMS >

      <XMLToDBMS Version="2.0" xmlns="http://www.xmlmiddleware.org/xmldbms/v2">
      <Options>
      <FormatClass DefaultForTypes="BIT"
      Class="org.xmlmiddleware.conversions.formatters.BooleanFormatter"/>
      <SimpleDateFormat DefaultForTypes="DATE" Pattern="MMM d, yyyy"/>
      <SimpleDateFormat DefaultForTypes="TIMESTAMP" Pattern="MMM d,
      yyyy h:mm:ss a"/>
      <SimpleDateFormat DefaultForTypes="TIME" Pattern="h:mm:ss a"/>
      <DecimalFormat DefaultForTypes="BIGINT TINYINT DOUBLE REAL FLOAT
      SMALLINT INTEGER DECIMAL NUMERIC" Pattern="#,##0.###"/>
      <FormatClass DefaultForTypes="LONGVARCHAR VARCHAR CHAR"
      Class="org.xmlmiddleware.conversions.formatters.CharFormatter"/>
      <FormatClass DefaultForTypes="BINARY VARBINARY LONGVARBINARY"
      Class="org.xmlmiddleware.conversions.formatters.NoFormatter"/>
      </Options>
      <Databases>
      <Database Name="Default">
      <Catalog>
      <Schema>
      <Table Name="msms_run_summary">
      <Column Name="base_name" DataType="VARCHAR"
      Length="255" Nullable="Yes"/>
      <Column Name="mrs_id" DataType="INTEGER" Nullable="No"/>
      <Column Name="msms_pipeline_analysis_id"
      DataType="INTEGER" Nullable="Yes"/>
      <Column Name="created" DataType="TIMESTAMP"
      Nullable="Yes"/>
      <Column Name="raw_data" DataType="VARCHAR"
      Length="255" Nullable="Yes"/>
      <Column Name="raw_data_type" DataType="VARCHAR"
      Length="255" Nullable="Yes"/>
      <ForeignKey
      Name="msms_pipeline_analysismsms_run_summary">
      <UseTable Name="msms_pipeline_analysis"/>
      <UseUniqueKey Name="PrimaryKey"/>
      <UseColumn Name="msms_pipeline_analysis_id"/>
      </ForeignKey>
      </Table>
      <Table Name="msms_pipeline_analysis">
      <Column Name="summary_xml" DataType="VARCHAR"
      Length="255" Nullable="Yes"/>
      <Column Name="date" DataType="VARCHAR" Length="255"
      Nullable="Yes"/>
      <Column Name="mpa_id" DataType="INTEGER" Nullable="No"/>
      <Column Name="created" DataType="TIMESTAMP"
      Nullable="Yes"/>
      <PrimaryKey>
      <UseColumn Name="mpa_id"/>
      </PrimaryKey>
      </Table>
      </Schema>
      </Catalog>
      </Database>
      </Databases>
      <Maps>
      <ClassMap>
      <ElementType Name="msms_run_summary"/>
      <ToClassTable Name="msms_run_summary"/>
      <PropertyMap TokenList="No" ContainsXML="No">
      <ElementType Name="base_name"/>
      <ToColumn Name="base_name"/>
      </PropertyMap>
      <PropertyMap TokenList="No" ContainsXML="No">
      <ElementType Name="mrs_id"/>
      <ToColumn Name="mrs_id"/>
      </PropertyMap>
      <PropertyMap TokenList="No" ContainsXML="No">
      <ElementType Name="msms_run_summary.created"/>
      <ToColumn Name="created"/>
      </PropertyMap>
      <PropertyMap TokenList="No" ContainsXML="No">
      <ElementType Name="raw_data_type"/>
      <ToColumn Name="raw_data_type"/>
      </PropertyMap>
      <PropertyMap TokenList="No" ContainsXML="No">
      <ElementType Name="raw_data"/>
      <ToColumn Name="raw_data"/>
      </PropertyMap>
      </ClassMap>
      <ClassMap>
      <ElementType Name="msms_pipeline_analysis"/>
      <ToClassTable Name="msms_pipeline_analysis"/>
      <PropertyMap TokenList="No" ContainsXML="No">
      <ElementType Name="summary_xml"/>
      <ToColumn Name="summary_xml"/>
      </PropertyMap>
      <PropertyMap TokenList="No" ContainsXML="No">
      <ElementType Name="mpa_id"/>
      <ToColumn Name="mpa_id"/>
      </PropertyMap>
      <PropertyMap TokenList="No" ContainsXML="No">
      <ElementType Name="date"/>
      <ToColumn Name="date"/>
      </PropertyMap>
      <PropertyMap TokenList="No" ContainsXML="No">
      <ElementType Name="created"/>
      <ToColumn Name="created"/>
      </PropertyMap>
      <RelatedClass KeyInParentTable="Unique">
      <ElementType Name="msms_run_summary"/>
      <UseUniqueKey Name="PrimaryKey"/>
      <UseForeignKey Name="msms_pipeline_analysismsms_run_summary"/>
      </RelatedClass>
      </ClassMap>
      </Maps>
      </XMLToDBMS>

      Rob wrote:

      > Hello,
      >
      > This problem is driving me nuts ...
      > I have a database and I wish to create the appropriate map file from
      > it.
      >
      > I run this command:
      >
      > java org.xmlmiddleware.xmldbms.tools.MapManager File1=parser.props
      > File2=db.props Input=Database Output=Map MapFile=my.map
      > RootTable=msms_pipeline_analysis FollowPrimaryKeys=Yes
      >
      >
      > My database contains the two tables below.
      >
      > Now, if I comment out the FOREIGN KEY statement in the second table
      > (below), I get no errors and my MapFile looks ok (it only has the
      > first table in it though). If I include the foreign key as below - I
      > get an error concerning XMLNameChecker. See full stack at end of this
      > message.
      >
      > Any ideas why this might be so?
      >
      >
      >
      > =============DATABASE==============================================
      >
      > create table msms_pipeline_analysis(
      >
      > mpa_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
      > summary_xml varchar(255) not null,
      > date varchar(255) not null,
      > created timestamp not null default current_timestamp
      >
      > )engine=innodb;
      >
      >
      >
      > create table msms_run_summary(
      >
      > mrs_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
      > msms_pipeline_analysis_id bigint not null,
      > base_name varchar(255) not null,
      > raw_data_type varchar(255) not null,
      > raw_data varchar(255) not null,
      > created timestamp not null default current_timestamp,
      >
      > FOREIGN KEY (msms_pipeline_analysis_id) REFERENCES
      > msms_pipeline_analysis(mpa_id)
      > )engine=innodb;
      >
      > =====================================================================
      >
      >
      >
      > java org.xmlmiddleware.xmldbms.tools.MapManager File1=parser.props
      > File2=db.props Input=Database Output=Map MapFile=my.map
      > RootTable=msms_pipeline_analysis FollowPrimaryKeys=Yes
      >
      > java.lang.NullPointerException
      > at
      > org.xmlmiddleware.xmldbms.maps.factories.XMLNameChecker.checkCharacter
      > s(XMLNameChecker.java:212)
      > at
      > org.xmlmiddleware.xmldbms.maps.factories.XMLNameChecker.checkName
      > (XMLNameChecker.java:177)
      > at
      > org.xmlmiddleware.xmldbms.maps.factories.XMLNameChecker.checkElementTy
      > peName(XMLNameChecker.java:116)
      > at
      > org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.getElemen
      > tTypeName(MapFactory_Database.java:1264)
      > at
      > org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.linkRemot
      > eTables(MapFactory_Database.java:865)
      > at
      > org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.processTa
      > ble(MapFactory_Database.java:714)
      > at
      > org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.processRe
      > moteTables(MapFactory_Database.java:913)
      > at
      > org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.processTa
      > ble(MapFactory_Database.java:715)
      > at
      > org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.processTa
      > bles(MapFactory_Database.java:567)
      > at
      > org.xmlmiddleware.xmldbms.maps.factories.MapFactory_Database.createMap
      > (MapFactory_Database.java:417)
      > at
      > org.xmlmiddleware.xmldbms.tools.MapManager.createMapFromDatabase
      > (MapManager.java:749)
      > at org.xmlmiddleware.xmldbms.tools.MapManager.dispatch
      > (MapManager.java:454)
      > at org.xmlmiddleware.xmldbms.tools.MapManager.main
      > (MapManager.java:348)
    Your message has been successfully submitted and would be delivered to recipients shortly.