You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Jan Krabbenbos <ja...@planet.nl> on 2003/10/02 09:36:36 UTC
OM generation problem
Hi,
I new to torque and torque-gen, so I now am trying to find out how I can use
and implement it (I'm using 3.1). I have an existing MySQL database, which I
want use. With torque-gen and the jdbc action I generated the schema and the
object model. When I now compile the generated java sources, it returns with
the error:
club.java:41: illegal start of expression
[javac] private long club_id = ;
There is no value inserted between '=' and ';' so therefor it can not be
compiled. I checked what could be the problem, and it seems to be the auto
increment in the table for club_id. With the autoincrement it generates the
following schema for the table 'club':
<table javaName="club" name="club">
<column default="" javaName="club_id" name="club_id"
primaryKey="true" required="true" type="BIGINT"/>
<column default="" javaName="name" name="name" size="100" type="VARCHAR"/>
<column default="" javaName="location" name="location"
size="100" type="VARCHAR"/>
<column default="" javaName="description" name="description"
size="255" type="VARCHAR"/>
<column default="" javaName="changed" name="changed" type="TIMESTAMP"/>
</table>
After changing the autoincrement in the MySQL to no for 'club_id' it generates
the following schema and the object model generated compiles!?!
<table javaName="club" name="club">
<column default="0" javaName="club_id" name="club_id"
primaryKey="true" required="true" type="BIGINT"/>
<column default="" javaName="name" name="name" size="100" type="VARCHAR"/>
<column default="" javaName="location" name="location"
size="100" type="VARCHAR"/>
<column default="" javaName="description" name="description"
size="255" type="VARCHAR"/>
<column default="" javaName="changed" name="changed" type="TIMESTAMP"/>
</table>
The difference is in the default-tag of the column 'club_id'. With the
autoincrement it is empty and without the autoincrement it is 0. Can anybody
tell me if this is a configuration problem or a bug?
--
Met vriendelijke groet,
Jan Krabbenbos
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: OM generation problem
Posted by Ryan Parr <ry...@thejamescompany.com>.
On Thu, 2003-10-02 at 01:36, Jan Krabbenbos wrote:
> Hi,
>
> I new to torque and torque-gen, so I now am trying to find out how I can use
> and implement it (I'm using 3.1). I have an existing MySQL database, which I
> want use. With torque-gen and the jdbc action I generated the schema and the
> object model. When I now compile the generated java sources, it returns with
> the error:
>
> club.java:41: illegal start of expression
> [javac] private long club_id = ;
>
> There is no value inserted between '=' and ';' so therefor it can not be
> compiled. I checked what could be the problem, and it seems to be the auto
> increment in the table for club_id. With the autoincrement it generates the
> following schema for the table 'club':
>
> <table javaName="club" name="club">
> <column default="" javaName="club_id" name="club_id"
> primaryKey="true" required="true" type="BIGINT"/>
> <column default="" javaName="name" name="name" size="100" type="VARCHAR"/>
> <column default="" javaName="location" name="location"
> size="100" type="VARCHAR"/>
> <column default="" javaName="description" name="description"
> size="255" type="VARCHAR"/>
> <column default="" javaName="changed" name="changed" type="TIMESTAMP"/>
> </table>
>
> After changing the autoincrement in the MySQL to no for 'club_id' it generates
> the following schema and the object model generated compiles!?!
>
> <table javaName="club" name="club">
> <column default="0" javaName="club_id" name="club_id"
> primaryKey="true" required="true" type="BIGINT"/>
> <column default="" javaName="name" name="name" size="100" type="VARCHAR"/>
> <column default="" javaName="location" name="location"
> size="100" type="VARCHAR"/>
> <column default="" javaName="description" name="description"
> size="255" type="VARCHAR"/>
> <column default="" javaName="changed" name="changed" type="TIMESTAMP"/>
> </table>
>
> The difference is in the default-tag of the column 'club_id'. With the
> autoincrement it is empty and without the autoincrement it is 0. Can anybody
> tell me if this is a configuration problem or a bug?
I'm also new to torque and was in the exact same situation 2 days ago.
I'm not sure how torque does it, since I'm also new, but if you specify
a default of 0 for your autoincrements, then I believe all your id's
will be 0.
What I did that seems to work (haven't really tested it yet, but it
compiles) is to continue to specify the autoIncrement attribute. but
remove the default attribute all together. So in one of my tables it
looks like this:
<column name="id" autoIncrement="true" required="true" primaryKey="true"
size="20" type="BIGINT" />
That seems to work.
I've attached a perl script that will reverse-engineer your existing
MySQL database. It supports foreign-keys for InnoDB, and will also check
out your indexes and unique indexes, which I didn't get from the "jdbc"
target in build-torque.xml. Maybe this could help you or a couple others
out there.
It's pretty rough, since it was a quick throw together for my own use.
Let me know if it works or doesn't work for you. And as always, patches
are welcome :)
Perl Script Prerequisites:
Modules (install these via 'perl -MCPAN -e "install $modname"')
---------------
DBI "perl -MCPAN -e 'install DBI'"
DBD::mysql "perl -MCPAN -e 'install DBD::mysql'"
Template "perl -MCPAN -e 'install Template'"
Other
---------------
A properly configured MySQL database