Subject Unable to create foreign keys
Author Geert Bevin
Hi,

I'm trying to create a structure that has foreign key constraints
between tables. While this seems already tricky to do manually in isql
(you need to ensure that only one connection is active while doing it),
I can't seems to find a way to do it through Jaybird at all.

This is some test code:

Class.forName("org.firebirdsql.jdbc.FBDriver").newInstance();
Connection connection = DriverManager
.getConnection("jdbc:firebirdsql:localhost/3050:/Volumes/Data/
firebird.gdb",
"sysdba", "masterkey");
try
{
Statement stmt1 = connection.createStatement();
try
{
stmt1.executeUpdate("CREATE TABLE test (id INTEGER NOT NULL PRIMARY
KEY)");
}
finally { stmt1.close(); }

Statement stmt2 = connection.createStatement();
try
{
stmt2.executeUpdate("CREATE TABLE test2 (testid INTEGER, FOREIGN KEY
(testid) REFERENCES test (id))");
}
finally { stmt2.close(); }

Statement stmt3 = connection.createStatement();
try
{
stmt3.executeUpdate("DROP TABLE test2");
}
finally { stmt3.close(); }

Statement stmt4 = connection.createStatement();
try
{
stmt4.executeUpdate("DROP TABLE test");
}
finally { stmt4.close(); }
}
finally { connection.close(); };

It always fails with:

org.firebirdsql.jdbc.FBSQLException: Resource Exception. unsuccessful
metadata update
object TEST is in use
Reason: unsuccessful metadata update
object TEST is in use
at
org.firebirdsql.jdbc.AbstractConnection.checkEndTransaction(AbstractConn
ection.java:849)
at
org.firebirdsql.jdbc.AbstractStatement.executeUpdate(AbstractStatement.j
ava:198)
at Firebird.main(Firebird.java:27)
at org.firebirdsql.gds.GDSException: unsuccessful metadata update
object TEST is in use
at org.firebirdsql.jgds.GDS_Impl.readStatusVector(GDS_Impl.java:1756)
at org.firebirdsql.jgds.GDS_Impl.receiveResponse(GDS_Impl.java:1709)
at
org.firebirdsql.jgds.GDS_Impl.isc_commit_transaction(GDS_Impl.java:586)
at
org.firebirdsql.jca.FBManagedConnectionFactory.commit(FBManagedConnectio
nFactory.java:681)
at
org.firebirdsql.jca.FBManagedConnection.internalCommit(FBManagedConnecti
on.java:391)
at
org.firebirdsql.jca.FBLocalTransaction.internalCommit(FBLocalTransaction
.java:149)
at
org.firebirdsql.jdbc.AbstractConnection.checkEndTransaction(AbstractConn
ection.java:845)
at
org.firebirdsql.jdbc.AbstractStatement.executeUpdate(AbstractStatement.j
ava:198)
at Firebird.main(Firebird.java:27)

Even when I just try to create the second table after having
disconnected and reconnected the connection, I still get the same
error. Any ideas how to make this work?

Thanks for the help,

Geert

--
Geert Bevin Uwyn bvba
"Use what you need" Avenue de Scailmont 34
http://www.uwyn.com 7170 Manage
gbevin[remove] at uwyn dot com Tel +32 64 84 80 03

PGP Fingerprint : 4E21 6399 CD9E A384 6619 719A C8F4 D40D 309F D6A9
Public PGP key : available at servers pgp.mit.edu, wwwkeys.pgp.net