Discussion:
[Middlegen-user] [BUG] NPE if a table has a FK of more than one column
Marco Papini
2002-06-27 12:44:06 UTC
Permalink
I've got a problem running Middlegen on my DB, where I've defined a
foreign key on two columns. That's the scenario:

Table A ( a1, a2, a3, a4 ) where PK is a1, a2
Table B ( b1, a1, a2, b2 ) where PK is b1 and FK is (a1, a2)

When running Middlegen, I get this error :

[middlegen] (middlegen.DbTable 197 ) There is no
column named a1,a2 in the table named b

Hope this is clear enough.

Marco
a***@netcom.no
2002-06-27 13:08:10 UTC
Permalink
I'll look at it. Can you send me the SQL too? I'd like to see how you
define the REFERENCE.

PS. I have done good progress with struts/jsp generation. It might be
valuable for your webwork/velocity stuff (that was you, wasn't it?).
I'll commit it one of these days.
DS.

Aslak

----- Original Message -----
From: Marco Papini <***@cinetica.it>
Date: Thursday, June 27, 2002 4:43 pm
Subject: [Middlegen-user] [BUG] NPE if a table has a FK of more than
one column
Post by Marco Papini
I've got a problem running Middlegen on my DB, where I've defined
a
Table A ( a1, a2, a3, a4 ) where PK is a1, a2
Table B ( b1, a1, a2, b2 ) where PK is b1 and FK is (a1, a2)
[middlegen] (middlegen.DbTable 197 ) There is no
column named a1,a2 in the table named b
Hope this is clear enough.
Marco
-------------------------------------------------------
ThinkGeek at http://www.ThinkGeek.com/
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Marco Papini
2002-06-27 13:24:03 UTC
Permalink
Here's the SQL (not really a usefull table ! ;) ) :

create table A (
a1 integer,
a2 integer,
a3 integer,
a4 integer,
primary key (a1, a2)
);

create table B (
b1 integer,
a1 integer,
a2 integer,
b2 integer,
primary key (b1)
);

alter table B add constraint fk_b1
foreign key (a1, a2)
references A(a1, a2)
;

I've tried it on PostgreSQL, but should be standard SQL.

PS: Good memory ! Yes, it me ! ;) I'm still working on WW/Velocity code,
but I've created a simple plugin. The problem is it's too specific to my
project. Are you available to look at the templates to make them more
flexible/general ?

Marco
Post by a***@netcom.no
I'll look at it. Can you send me the SQL too? I'd like to see how you
define the REFERENCE.
PS. I have done good progress with struts/jsp generation. It might be
valuable for your webwork/velocity stuff (that was you, wasn't it?).
I'll commit it one of these days.
DS.
Aslak
Aslak Hellesoy
2002-06-28 12:35:02 UTC
Permalink
Hi again Marco.

I tried to create these tables in the hsqldb database (see
middlegen/src/sql/marco.sql) and got no NPE problems. See the screenshot.
Therefore I assume the problem is related to your JDBC driver.

I realise that there should not be two relations, only one, but that's
another issue. Supporting this requires some GUI work too, as I'll have to
draw relations like this:

--\
\--------
/
--/

What do you think? Can we blame your JDBC driver on this NPE issue?

/Aslak
-----Original Message-----
Papini
Sent: 27. juni 2002 17:23
Subject: Re: [Middlegen-user] [BUG] NPE if a table has a FK of more than
one column
create table A (
a1 integer,
a2 integer,
a3 integer,
a4 integer,
primary key (a1, a2)
);
create table B (
b1 integer,
a1 integer,
a2 integer,
b2 integer,
primary key (b1)
);
alter table B add constraint fk_b1
foreign key (a1, a2)
references A(a1, a2)
;
I've tried it on PostgreSQL, but should be standard SQL.
PS: Good memory ! Yes, it me ! ;) I'm still working on WW/Velocity code,
but I've created a simple plugin. The problem is it's too specific to my
project. Are you available to look at the templates to make them more
flexible/general ?
Marco
Post by a***@netcom.no
I'll look at it. Can you send me the SQL too? I'd like to see how you
define the REFERENCE.
PS. I have done good progress with struts/jsp generation. It might be
valuable for your webwork/velocity stuff (that was you, wasn't it?).
I'll commit it one of these days.
DS.
Aslak
-------------------------------------------------------
ThinkGeek at http://www.ThinkGeek.com/
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Marco Papini
2002-06-28 12:57:11 UTC
Permalink
Well, I can't say for sure, but I don't think it's a problem of JDBC
driver. It seems to be a different behaviour: the problem with
PostgreSQL is that it returns a single relation with an array of
origin/destination fields. That's my idea, 'cause the msg was :

There is no column named a1,a2 in the table named b

So the driver can read the column names, but Middlegen searches wrong
column name ("a1,a2" instead of "a1" AND "a2").

Could it be that you expect a String and you get a String[] from the
driver ?

Anyway, I'll try another JDBC driver/database and I'll let you know.

I think that you should draw a single line for the relation, 'cause you
probably won't need to enable/disable single relation generation.

Thanks

Marco
Post by Aslak Hellesoy
Hi again Marco.
I tried to create these tables in the hsqldb database (see
middlegen/src/sql/marco.sql) and got no NPE problems. See the screenshot.
Therefore I assume the problem is related to your JDBC driver.
I realise that there should not be two relations, only one, but that's
another issue. Supporting this requires some GUI work too, as I'll have to
--\
\--------
/
--/
What do you think? Can we blame your JDBC driver on this NPE issue?
/Aslak
Aslak Hellesoy
2002-06-28 13:15:05 UTC
Permalink
Can you send me the full debug output from Middlegen? (I'm especially
interested in the debug from lines 233-236 in MiddlegenPopulator.java)

Ciao
Aslak
-----Original Message-----
Papini
Sent: 27. juni 2002 16:44
Subject: [Middlegen-user] [BUG] NPE if a table has a FK of more than one
column
I've got a problem running Middlegen on my DB, where I've defined a
Table A ( a1, a2, a3, a4 ) where PK is a1, a2
Table B ( b1, a1, a2, b2 ) where PK is b1 and FK is (a1, a2)
[middlegen] (middlegen.DbTable 197 ) There is no
column named a1,a2 in the table named b
Hope this is clear enough.
Marco
-------------------------------------------------------
ThinkGeek at http://www.ThinkGeek.com/
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Aslak Hellesoy
2002-06-28 13:19:06 UTC
Permalink
-----Original Message-----
Papini
Sent: 28. juni 2002 16:56
To: Aslak Hellesoy
Subject: Re: [Middlegen-user] [BUG] NPE if a table has a FK of more than
one column
Well, I can't say for sure, but I don't think it's a problem of JDBC
driver. It seems to be a different behaviour: the problem with
PostgreSQL is that it returns a single relation with an array of
There is no column named a1,a2 in the table named b
So the driver can read the column names, but Middlegen searches wrong
column name ("a1,a2" instead of "a1" AND "a2").
Could it be that you expect a String and you get a String[] from the
driver ?
Exactly. Look at MiddlegenPopulator lines 225 and 232. Also look at:

http://java.sun.com/j2se/1.4/docs/api/java/sql/DatabaseMetaData.html#getImpo
rtedKeys(java.lang.String, java.lang.String, java.lang.String)

It seems your driver returns a one-row resultset with a comma-separated list
of columns when I ask for FKCOLUMN_NAME.
This is wrong. It should be returning a two-row resultset which returns the
name of a single column when I ask for FKCOLUMN_NAME.

Therefore I assume the JDBC driver is buggy (it doesn't behave like Sun's
API docs say it should behave).

Exactly what driver are you using? What database?

/Aslak
Anyway, I'll try another JDBC driver/database and I'll let you know.
I think that you should draw a single line for the relation, 'cause you
probably won't need to enable/disable single relation generation.
Thanks
Marco
Post by Aslak Hellesoy
Hi again Marco.
I tried to create these tables in the hsqldb database (see
middlegen/src/sql/marco.sql) and got no NPE problems. See the
screenshot.
Post by Aslak Hellesoy
Therefore I assume the problem is related to your JDBC driver.
I realise that there should not be two relations, only one, but that's
another issue. Supporting this requires some GUI work too, as
I'll have to
Post by Aslak Hellesoy
--\
\--------
/
--/
What do you think? Can we blame your JDBC driver on this NPE issue?
/Aslak
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Caffeinated soap. No kidding.
http://thinkgeek.com/sf
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Gordon Luk
2002-06-29 06:59:03 UTC
Permalink
Hi Middlegen User,

If you using postgresql , and found NPE problem, take a try other
one of postgrsql JDBC.
URL is http://jxdbcon.sourceforge.net/


Gordon

PS:
Aslak, do you have any idea/advise about my pervoius mesagge on
28-6-2002 09:32 am.
Marco Papini
2002-07-01 05:52:04 UTC
Permalink
I've made some tests. The driver jxDBCon-jdbc3-0.9z.jar works fine with
normal relation, but seems not ok with relation on multiple column
(Middlegen displays no relation at all). With the developer driver from
postgresql site doesn't display any relation. With the latest stable
version of the driver I get the no-column problem reading tables.
That's after CVS update on friday.

I've also tested with Oracle: no problem after CVS update, everything
seems to be ok.

Marco
Post by Gordon Luk
Hi Middlegen User,
If you using postgresql , and found NPE problem, take a try other one
of postgrsql JDBC.
URL is http://jxdbcon.sourceforge.net/
Gordon
Aslak Hellesoy
2002-07-02 21:21:05 UTC
Permalink
(This is cross-posted to the postgresql JDBC list). Postgres guys, please
see my last comment.
-----Original Message-----
Papini
Sent: 1. juli 2002 09:47
To: Gordon Luk
Subject: Re: [Middlegen-user] Try other one of Postgresql JDBC Driver
(no NPE)
I've made some tests. The driver jxDBCon-jdbc3-0.9z.jar works fine with
normal relation, but seems not ok with relation on multiple column
The jxDBCon-jdbc3-0.9z.jar driver is obviously buggy with respect to
relations with multiple columns. MetaData isn't the most heavily used part
of the JDBC API, so they are probably unaware of it.

See my other mail on the same subject:
http://sourceforge.net/mailarchive/message.php?msg_id=1756797

A bug report has been filed with the jxdbcon project:
http://sourceforge.net/tracker/index.php?func=detail&aid=576654&group_id=258
45&atid=385447
(Middlegen displays no relation at all). With the developer driver from
postgresql site doesn't display any relation. With the latest stable
Well, the pgjdbc2.jar driver (http://jdbc.postgresql.org/download.html)
seems to be buggy too. I couldn't find a bug tracker for it, so the bug
report for you guys is this mail and this link (again).
version of the driver I get the no-column problem reading tables.
That's after CVS update on friday.
I've also tested with Oracle: no problem after CVS update, everything
seems to be ok.
Marco
Post by Gordon Luk
Hi Middlegen User,
If you using postgresql , and found NPE problem, take a try
other one
Post by Gordon Luk
of postgrsql JDBC.
URL is http://jxdbcon.sourceforge.net/
Gordon
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Marco Papini
2002-07-03 12:23:05 UTC
Permalink
Some more info on JDBC driver: I've tried jxDBCon-jdbc3-0.9z.jar driver
with latest CVS update and it seems to work correctly. I think I made
some mistake in my previous tests, so this driver should be ok (I'm
sorry ! ).

I've also noticed that now Middlegen displays a single relation with Y
ends for relation on 2 fk. (that's nice :) ).
The only curious thing is that n-m relation in some cases are not drawn
correcly: the ends appears like this :

/
----/

It seems it draws a Y end on just one field.

Bye

Marco
Post by Aslak Hellesoy
(This is cross-posted to the postgresql JDBC list). Postgres guys, please
see my last comment.
-----Original Message-----
Papini
Sent: 1. juli 2002 09:47
To: Gordon Luk
Subject: Re: [Middlegen-user] Try other one of Postgresql JDBC Driver
(no NPE)
I've made some tests. The driver jxDBCon-jdbc3-0.9z.jar works fine with
normal relation, but seems not ok with relation on multiple column
The jxDBCon-jdbc3-0.9z.jar driver is obviously buggy with respect to
relations with multiple columns. MetaData isn't the most heavily used part
of the JDBC API, so they are probably unaware of it.
http://sourceforge.net/mailarchive/message.php?msg_id=1756797
http://sourceforge.net/tracker/index.php?func=detail&aid=576654&group_id=258
45&atid=385447
(Middlegen displays no relation at all). With the developer driver from
postgresql site doesn't display any relation. With the latest stable
Well, the pgjdbc2.jar driver (http://jdbc.postgresql.org/download.html)
seems to be buggy too. I couldn't find a bug tracker for it, so the bug
report for you guys is this mail and this link (again).
Dave Cramer
2002-07-08 11:03:02 UTC
Permalink
Aslak,

Did you get this sorted out, I have done quite a bit of work on the
databasemetadata.

Dave
Post by Aslak Hellesoy
(This is cross-posted to the postgresql JDBC list). Postgres guys, please
see my last comment.
-----Original Message-----
Papini
Sent: 1. juli 2002 09:47
To: Gordon Luk
Subject: Re: [Middlegen-user] Try other one of Postgresql JDBC Driver
(no NPE)
I've made some tests. The driver jxDBCon-jdbc3-0.9z.jar works fine with
normal relation, but seems not ok with relation on multiple column
The jxDBCon-jdbc3-0.9z.jar driver is obviously buggy with respect to
relations with multiple columns. MetaData isn't the most heavily used part
of the JDBC API, so they are probably unaware of it.
http://sourceforge.net/mailarchive/message.php?msg_id=1756797
http://sourceforge.net/tracker/index.php?func=detail&aid=576654&group_id=258
45&atid=385447
(Middlegen displays no relation at all). With the developer driver from
postgresql site doesn't display any relation. With the latest stable
Well, the pgjdbc2.jar driver (http://jdbc.postgresql.org/download.html)
seems to be buggy too. I couldn't find a bug tracker for it, so the bug
report for you guys is this mail and this link (again).
version of the driver I get the no-column problem reading tables.
That's after CVS update on friday.
I've also tested with Oracle: no problem after CVS update, everything
seems to be ok.
Marco
Post by Gordon Luk
Hi Middlegen User,
If you using postgresql , and found NPE problem, take a try
other one
Post by Gordon Luk
of postgrsql JDBC.
URL is http://jxdbcon.sourceforge.net/
Gordon
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
Aslak Hellesøy
2002-07-08 12:09:05 UTC
Permalink
Hi Dave,

I reported this issue on behalf of some of the Middlegen users, and I
haven't tried PostgreSQL/pgjdbc2.jar myself yet. I have downloaded them, and
I'll go through some manuals and hopefully give you feedback in a day or
two.

Thanks,
Aslak
-----Original Message-----
Sent: 8. juli 2002 15:01
To: Aslak Hellesoy
Subject: Re: [JDBC] [Middlegen-user] Try other one of Postgresql JDBC
Driver
Aslak,
Did you get this sorted out, I have done quite a bit of work on the
databasemetadata.
Dave
Post by Aslak Hellesoy
(This is cross-posted to the postgresql JDBC list). Postgres
guys, please
Post by Aslak Hellesoy
see my last comment.
-----Original Message-----
Papini
Sent: 1. juli 2002 09:47
To: Gordon Luk
Subject: Re: [Middlegen-user] Try other one of Postgresql JDBC Driver
(no NPE)
I've made some tests. The driver jxDBCon-jdbc3-0.9z.jar works
fine with
Post by Aslak Hellesoy
normal relation, but seems not ok with relation on multiple column
The jxDBCon-jdbc3-0.9z.jar driver is obviously buggy with respect to
relations with multiple columns. MetaData isn't the most
heavily used part
Post by Aslak Hellesoy
of the JDBC API, so they are probably unaware of it.
http://sourceforge.net/mailarchive/message.php?msg_id=1756797
http://sourceforge.net/tracker/index.php?func=detail&aid=576654&gr
oup_id=258
Post by Aslak Hellesoy
45&atid=385447
(Middlegen displays no relation at all). With the developer
driver from
Post by Aslak Hellesoy
postgresql site doesn't display any relation. With the latest stable
Well, the pgjdbc2.jar driver (http://jdbc.postgresql.org/download.html)
seems to be buggy too. I couldn't find a bug tracker for it, so the bug
report for you guys is this mail and this link (again).
version of the driver I get the no-column problem reading tables.
That's after CVS update on friday.
I've also tested with Oracle: no problem after CVS update, everything
seems to be ok.
Marco
Post by Gordon Luk
Hi Middlegen User,
If you using postgresql , and found NPE problem, take a try
other one
Post by Gordon Luk
of postgrsql JDBC.
URL is http://jxdbcon.sourceforge.net/
Gordon
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/users-lounge/docs/faq.html
Loading...