db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Monroe <mon...@dukece.com>
Subject RE: newbie question about postgres: nextval
Date Mon, 26 Jan 2009 16:16:05 GMT
OK, the part about the jdbc task clears a lot up.  This task does
the best it can using the standard meta info supplied by the 
JDBC drivers.  Since this is a standard across all the various
DB server types, there are some limitations when it comes to various
"pseudo" standards that Torque supports, like native autoincrement 
fields (and offset and limit to name some others).

Native autoincrement is actually not an SQL standard.  However, since 
most DB servers have a method of autoincrementing fields built in and 
auto-incrementing index fields is commonly used in existing schemas, 
Torque supports this "pseudo" standard in its runtime and SQL creation.
But since this is implemented and reported very differently by all the
JDBC drivers (if at all), the JDBC task can't create the correct XML
given the information available.

This is what is causing your problems.  The bottom line is that the 
JDBC task output should always be considered a starting point that
will need to be refined to match the actual schema needs.

In general, for autoincrement id fields coming out of the JDBC task, 
you will need to decide which method to use with automatic id fields. 
This is done via the defaultIdMethod attribute on the database tag  or 
the idMethod attribute on the specific table tag.  The choices are 
idbroker (Torque's works everywhere method), native (the DB server's 
native method) or none.  In your case, you want native.

Next you will need to identify the autoincrement fields and modify
them to include the autoincrement="true" attribute and drop any
default values.

FWIW, some other "gotchas" from the JDBC task that come to mind are:

If you care about creating the tables via Torque, this does not 
create any Index or Unique information (JDBC doesn't supply this).  
You will have to add these in manually.

The table ordering may not meet the requirement that foreign keys
be defined prior to their use.  So you may need to move some 
table definitions around to make sure the tables with keys come
first.

It sounds like a lot of work, but in general, it takes only a
few minutes (or can be automated for your specific DB standard).
Just remember that this is a small amount of time compared to what 
it would take to write all the code that gets generated.




> -----Original Message-----
> From: Ivano Luberti [mailto:luberti@archicoop.it]
> Sent: Monday, January 26, 2009 10:15 AM
> To: Apache Torque Users List
> Subject: Re: newbie question about postgres: nextval
> 
> Here it is .
> In my prev message I didn't said that , I have defined the db using the
> server , then I have generated the schema using the jdbc ant task and the
> classes using the om ant task.
> I don't want to define myself the shema file because I'm more famliar
> with SQL and then I don't want to make Torque create or modify my DDL.
> Finally I use Torque 3.3 version and the generator directly without using
> Maven.
> 
> 
> 
> Thomas Fischer ha scritto:
> >> I'm using postgres to generate torque classes but the automatic
> >> generation seems to make a few mistakes.
> >> In the base class I found this java statement
> >>
> >> private int pkAnagrafica =
> >> nextval('anagrafica_pk_anagrafica_seq'::regclass);
> >>
> >> which is marked as wrong by the compiler.
> >>
> >> The same happens in the copyobject method of the same class:
> >>
> >> copyObj.setPkAnagrafica(
> >>
> > nextval('anagrafica_pk_anagrafica_seq'::regclass));
> >
> >> Is there a way to stop Torque generating these bad statements ?
> >>
> >
> > Can you send the schema definition which you use for the table in
> > question ? This would ease diagnostics. I suspect that you use a
> > default value for the id; this is not necessary.
> >
> >    Thomas
> >
> 
> --
> ==================================================
> Archimede Informatica NEWS!
> ==================================================
> 
> Realizzato il Sistema Integrato per la biglietteria della Torre di Pisa:
> prenotazione, vendita, pre-vendita ed emissione dei biglietti di ingresso
> alla Torre sia online che presso le biglietterie dislocate sulla piazza:
> 
> _http://www.opapisa.it/boxoffice
> 
> _Partner del Progetto Ci-Tel "Front office Telematico per il cittadino"
> Ente Coordinatore Comune di Pisa
> 
> _http://www.comune.pisa.it/doc/e-government.htm
> 
> 
> _==================================================
> dott. Ivano Mario Luberti
> Archimede Informatica societa' cooperativa a r. l.
> Sede Operativa
> Via Gereschi 36 - 56126- Pisa
> tel.: +39-050- 580959
> tel/fax: +39-050-9711344
> e-mail: archimede@archicoop.it
> web: _http://www.archicoop.it
> 
> 
> _ <http://www.archicoop.it/>__ <http://www.archicoop.it/>
DukeCE Privacy Statement:
Please be advised that this e-mail and any files transmitted with
it are confidential communication or may otherwise be privileged or
confidential and are intended solely for the individual or entity
to whom they are addressed. If you are not the intended recipient
you may not rely on the contents of this email or any attachments,
and we ask that you please not read, copy or retransmit this
communication, but reply to the sender and destroy the email, its
contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is
strictly prohibited.

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


Mime
View raw message