db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chiu Yee Weay" <ywc...@paradigm.com.my>
Subject RE: Problem with jdbc 2 XML
Date Thu, 06 Nov 2003 12:59:42 GMT

I do not know how's mysql's behavior, but looking at the source file,
this might be caused by the following conditions :

 - foreign keys' name is not null
 - same foreign keys' name for different foreign tables

So, instead of using the foreign key name, I would recommend using the
foreign table name instead.

Here's my refined getForeignKeys method in TorqueJDBCTransformTask.java

     * Retrieves a list of foreign key columns for a given table.
     * @param dbMeta JDBC metadata.
     * @param tableName Table from which to retrieve FK information.
     * @return A list of foreign keys in <code>tableName</code>.
     * @throws SQLException
    public Collection getForeignKeys(DatabaseMetaData dbMeta, String
        throws SQLException
        Hashtable fks = new Hashtable();
        ResultSet foreignKeys = null;
            foreignKeys = dbMeta.getImportedKeys(null, dbSchema,
            while (foreignKeys.next())
                String refTableName = foreignKeys.getString(3);
//referenced table name
                String refColumnName = foreignKeys.getString(4);
//foreign column
                String localColumnName = foreignKeys.getString(8);
//local column

                Object[] fk = (Object[]) fks.get(refTableName);
                List refs;
                if (fk == null)
                    fk = new Object[2];
                    fk[0] = refTableName;
                    refs = new ArrayList();
                    refs = (ArrayList) fk[1];
                String[] ref = new String[2];
                ref[0] = localColumnName;
                ref[1] = refColumnName;
                fk[1] = refs;
                fks.put(refTableName, fk);
            if (foreignKeys != null)
        return fks.values();


Chiu Yee Weay
Systems Engineer
Paradigm Systems Sdn Bhd

-----Original Message-----
From: Amine Bousta [mailto:abousta@lxsolutions.com] 
Sent: Thursday, November 06, 2003 12:34 AM
To: Apache Torque Users List
Subject: Problem with jdbc 2 XML


I'm experiencing a lot of problems by trying to generate an xml schema
a sql file.
The last one is :
I'm using Mysql with InnoDB tables and foreign keys.
I'm trying to launch ant on build-torque.xml with the "jdbc" option.
When a table A has a foreign key into a table B and another into table
C, it
generates :
<foreign-key foreignTable="B">
	<reference foreign="id" local="B_id"/>
	<reference foreign="id" local="C_id"/>

instead of :
<foreign-key foreignTable="B">
	<reference foreign="id" local="B_id"/>
<foreign-key foreignTable="C">
	<reference foreign="id" local="C_id"/>

as expected.

If anybody knows a workaround I'd really appreciate :)

Thank you
PS : Is this the good place here to report Torque bugs or do I have to
them in a bug database?

To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

[ Scanned by JARING E-Mail Virus Scanner ( http://www.jaring.my ) ]

To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org

View raw message